// Slower C++ solution:
#include <iostream>

#include <queue>

#include <cstring>

const int maxn=1010;

using namespace std;

struct Node {

	int x,y;

};

queue <Node> Q;

int a[maxn][maxn],d[maxn][maxn];

int vis[maxn][maxn];

int main(){

	memset(vis,0,sizeof(vis));

	memset(d,0,sizeof(d));

	ios::sync_with_stdio(false);

	cin.tie(0);

	int h,w;

	cin >> h>>w;

	for(int i=1;i<=h;i++){

		string s;

		cin >> s;

		for (int j=0;j<w;j++) {

			if (s[j] == '#'){

				a[i][j+1] = 1;

				Q.push((Node){i,j+1});

				vis[i][j+1] = 1;

			}else a[i][j+1] = 0;

			// a[i][j+1] = s[j]=='h'?1:0;



		}

	}



	int cnt = 0;

	while (!Q.empty()){

		Node p=Q.front();

		Q.pop();

		if (p.x>1 && !vis[p.x-1][p.y]){

			d[p.x-1][p.y] = d[p.x][p.y] + 1;

			Q.push((Node){p.x-1,p.y});

			vis[p.x-1][p.y] = 1;

		}

		if (p.y>1 && !vis[p.x][p.y-1]){

			d[p.x][p.y-1] = d[p.x][p.y] + 1;

			Q.push((Node){p.x,p.y-1});

			vis[p.x][p.y-1] = 1;

		}

		if (p.x<h && !vis[p.x+1][p.y]){

			d[p.x+1][p.y] = d[p.x][p.y] + 1;

			Q.push((Node){p.x+1,p.y});

			vis[p.x+1][p.y] = 1;

		}

		if (p.y<w && !vis[p.x][p.y+1]){

			d[p.x][p.y+1] = d[p.x][p.y] + 1;

			Q.push((Node){p.x,p.y+1});

			vis[p.x][p.y+1] = 1;

		}

	}

	int ans=0;

	// for (int i=1;i<=h;i++){

	// 	for (int j=1;j<=w;j++) ans=max(ans,d[i][j]),cout << d[i][j]<<' ';

	// 	cout << endl;

	// }

	for (int i=1;i<=h;i++)

		for (int j=1;j<=w;j++) ans=max(ans,d[i][j]);

	

	cout << ans;

}

// Faster C++ solution for the same problem (measured speedup: 9.613074835892075x):
#include <iostream>

#include<cstring>

#include<algorithm>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T>

void read(T &x){

    x=0;

    int flag=1;

    char c=getchar();

    while(c=='-'){

        flag=-1;

        c=getchar();

    }

    while(c>='0'&&c<='9'){

        x=x*10+c-'0';

        c=getchar();

    }

    x*=flag;

}

struct node{

    int x,y,id;

}q[1000010];

    int n,m,cnt=0,head=0;

    char mp[1010][1010]={'\0'};



int main()

{

    cin>>n>>m;

    rep(i,1,n)rep(j,1,m){

        cin>>mp[i][j];

        if(mp[i][j]=='#'){

            q[cnt].x=i;

            q[cnt].y=j;

            q[cnt++].id=0;

        }

    }

    while(head<cnt){

        if(q[head].x>1&&mp[q[head].x-1][q[head].y]=='.'){

            mp[q[head].x-1][q[head].y]='#';

            q[cnt].x=q[head].x-1;

            q[cnt].y=q[head].y;

            q[cnt++].id=q[head].id+1;

        }

        if(q[head].x<n&&mp[q[head].x+1][q[head].y]=='.'){

            mp[q[head].x+1][q[head].y]='#';

            q[cnt].x=q[head].x+1;

            q[cnt].y=q[head].y;

            q[cnt++].id=q[head].id+1;

        }

        if(q[head].y>0&&mp[q[head].x][q[head].y-1]=='.'){

            mp[q[head].x][q[head].y-1]='#';

            q[cnt].x=q[head].x;

            q[cnt].y=q[head].y-1;

            q[cnt++].id=q[head].id+1;

        }

        if(q[head].y<m&&mp[q[head].x][q[head].y+1]=='.'){

            mp[q[head].x][q[head].y+1]='#';

            q[cnt].x=q[head].x;

            q[cnt].y=q[head].y+1;

            q[cnt++].id=q[head].id+1;

        }

        head++;

    }

    cout<<q[head-1].id;

    return 0;

}