#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
int h,w,x,y,nx,ny,t,r,a[1010][1010],dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char c;
int main(){
  queue<tuple<int,int,int>>que;
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>c;
    a[i][j]=99999999;
    if(c=='#')que.emplace(i,j,0);
  }
  while(!que.empty()){
    tie(y,x,t)=que.front();que.pop();
    if(a[y][x]>t){
      a[y][x]=t;
      r=max(r,t);
      rep(i,4){
        ny=y+dy[i];nx=x+dx[i];
        if(nx<0||ny<0||nx>=w||ny>=h)continue;
        que.emplace(ny,nx,t+1);
      }
    }
  }
  cout<<r;
}