// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int to[4][2]={-1,0,

               1,0,

               0,-1,

               0,1};

int vis[1005][1005];

int news[1005][1005];

string s[1005];

int h,w;

int ans;

int x,y;

struct node

{

    int x,y,step;

};

void bfs()

{

    queue<node> q;

    node b;

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

    {

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

        {

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

            {

                b.step=0;

                b.x=i;

                b.y=j;

                q.push(b);

            }

        }

    }

    while(!q.empty())

    {

        b=q.front();

        q.pop();

        int flag=0;

        for(int i=0;i<4;i++)

        {

            int xx=b.x+to[i][0];

            int yy=b.y+to[i][1];

            if(0<=xx&&xx<h&&0<=yy&&yy<w)

            {

                if(s[xx][yy]=='.')

                {

                    s[xx][yy]='#';

                    node tmp;

                    tmp.x=xx;

                    tmp.y=yy;

                    tmp.step=b.step+1;

                    ans=max(ans,tmp.step);

                    q.push(tmp);

                }

            }

        }

    }

    cout<<ans<<endl;

}



int main()

{

    cin>>h>>w;

    ans=0;

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

    for(int i=0;i<h;i++) cin>>s[i];

    bfs();

    /*while(1)

    {

        memset(news,0,sizeof(n));

        sum=0;

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

        {

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

            {

                if(s[i][j]=='#') sum++;

            }

        }

        if(sum==h*w) break;

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

        {

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

            {

                if(s[i][j]=='#'&&!vis[i][j]&&!news[i][j])

                {

                    vis[i][j]=1;

                    for(int k=0;k<4;k++)

                    {

                        int xx=i+to[k][0];

                        int yy=j+to[k][1];

                        if(0<=xx&&xx<h&&0<=yy&&yy<w)

                        {

                            if(s[xx][yy]=='.')

                            {

                                s[xx][yy]='#';

                                news[xx][yy]=1;

                            }

                        }

                    }

                }

            }

        }

        ans++;

//        for(int i=0;i<h;i++)

//        {

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

//                cout<<s[i][j]<<" ";

//            cout<<endl;

//        }



    }*/

    /*for(int i=0;i<h;i++)

    {

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

            cout<<s[i][j]<<" ";

        cout<<endl;

    }

    */

    //cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

using namespace std;

typedef long long LL;

typedef pair<int,int> pii;

typedef vector<int> vi;



template<class T> inline T re(){

	T N = 0; char c = getchar(); bool neg = 0;

	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';

	for (; c >= '0' && c <= '9'; c = getchar())

		N = (N<<3)+(N<<1) + c - '0';

	return neg ? -N : N;

}



int h, w;

char g[1005][1005];

int d[1005][1005];

queue<pii> q;



int dr[] = {1, 0, -1, 0};

int dc[] = {0, 1, 0, -1};

inline bool ins(int r, int c){

	return 1 <= r && r <= h && 1 <= c && c <= w;

}

int main(){

	scanf("%d %d", &h, &w);

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

		scanf("%s", g[i] + 1);

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

		d[i][j] = 5000 * (g[i][j] == '.' ? 1 : (q.emplace(i,j), 0));

	while (!q.empty()){

		pii u = q.front(); q.pop();

		for (int i = 0; i < 4; i++){

			int r = u.fi + dr[i], c = u.se + dc[i];

			if (ins(r, c) && d[r][c] > d[u.fi][u.se] + 1){

				d[r][c] = d[u.fi][u.se] + 1;

				q.emplace(r, c);

			}

		}

	}

	int mx = 0;

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

		mx = max(mx, d[i][j]);

	printf("%d\n", mx);

	return 0;

}


// Fastest known solution for this problem: