#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> hw(h);
  for(int i=0; i<h; ++i) cin >> hw[i];
  queue<P> que;
  vector<vector<int>> dis(h, vector<int>(w, -1));
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    if(hw[i][j] == '#'){
      que.push(make_pair(i,j));
      dis[i][j] = 0;
    }
  }
  int ans = 0;
  while(!que.empty()){
    int x, y;
    tie(x,y) = que.front();
    que.pop();
    if(x>0 && dis[x-1][y] == -1){
      dis[x-1][y] = dis[x][y] + 1;
      ans = max(ans, dis[x-1][y]);
      que.push(make_pair(x-1,y));
    }
    if(x<h-1 && dis[x+1][y] == -1){
      dis[x+1][y] = dis[x][y] + 1;
      ans = max(ans, dis[x+1][y]);
      que.push(make_pair(x+1,y));
    }
    if(y>0 && dis[x][y-1] == -1){
      dis[x][y-1] = dis[x][y] + 1;
      ans = max(ans, dis[x][y-1]);
      que.push(make_pair(x,y-1));
    }
    if(y<w-1 && dis[x][y+1] == -1){
      dis[x][y+1] = dis[x][y] + 1;
      ans = max(ans, dis[x][y+1]);
      que.push(make_pair(x,y+1));
    }
  }
  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){ 
  if(A[i][j]=='#'){  B[i][j]=1; C.push_back(make_pair(i, j)); } 
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
}