#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
struct dimcomp2{
  int B;
  dimcomp2(){
  }
  dimcomp2(int b){
    B = b;
  }
  dimcomp2(int a, int b){
    B = b;
  }
  inline void set(int b){
    B = b;
  }
  inline void set(int a, int b){
    B = b;
  }
  inline int mask(int a, int b){
    return a * B + b;
  }
  inline int operator()(int a, int b){
    return a * B + b;
  }
  inline void para(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
  inline void operator()(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
}
;
int X;
int Y;
char A[1000][1002];
int dist[1000][1000];
int q[1000000];
int qs;
int qe;
dimcomp2 dm;
int main(){
  int i;
  int j;
  int k;
  int si;
  int sj;
  int d;
  int res;
  int di[4] = {-1,1,0,0};
  int dj[4] = {0,0,-1,1};
  rd(X);
  rd(Y);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(X);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  dm.set(X,Y);
  for(i=(0);i<(X);i++){
    for(j=(0);j<(Y);j++){
      dist[i][j] = -1;
    }
  }
  for(i=(0);i<(X);i++){
    for(j=(0);j<(Y);j++){
      if(A[i][j]=='#'){
        dist[i][j] = 0;
        q[qe++] = dm(i,j);
      }
    }
  }
  while(qs<qe){
    dm(q[qs++], i, j);
    res = dist[i][j];
    for(d=(0);d<(4);d++){
      si = i + di[d];
      sj = j + dj[d];
      if(si < 0 || sj < 0 || si >= X || sj >= Y || dist[si][sj] >= 0){
        continue;
      }
      dist[si][sj] = res + 1;
      q[qe++] = dm(si, sj);
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int X, Y; char A[1000][1002];
// int dist[1000][1000];
// int q[1d6], qs, qe;
// dimcomp2 dm;
// {
//   int i, j, k, si, sj, d, res;
//   int di[4] = {-1,1,0,0};
//   int dj[4] = {0,0,-1,1};
// 
//   rd(X,Y,A(X));
//   dm.set(X,Y);
//   rep(i,X) rep(j,Y) dist[i][j] = -1;
//   rep(i,X) rep(j,Y) if(A[i][j]=='#') dist[i][j] = 0, q[qe++] = dm(i,j);
// 
//   while(qs<qe){
//     dm(q[qs++], i, j);
//     res = dist[i][j];
//     rep(d,4){
//       si = i + di[d];
//       sj = j + dj[d];
//       if(si < 0 || sj < 0 || si >= X || sj >= Y || dist[si][sj] >= 0) continue;
//       dist[si][sj] = res + 1;
//       q[qe++] = dm(si, sj);
//     }
//   }
//   wt(res);
// }


Measured memory_bytes: 9088