// Slower C++ solution:
#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;

}


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



using namespace std;



int n, m, a[1005][1005];

pair<int,int> Q[1000005];

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

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

int maxim = 1, in, sf;



void bordare()

{

    for (int i=0;i<=n+1;i++)

        a[i][0] = a[i][m+1] = 1;

    for (int i=0;i<=m+1;i++)

        a[0][i] = a[n+1][i] = 1;

}



void lee();



int main()

{

    int i, j;

    char c;



    cin >> n >> m;

    for (i=1;i<=n;i++)

        for (j=1;j<=m;j++)

        {

            cin >> c;

            if (c == '#')

                a[i][j] = 1;

        }

    bordare();

    for (i=1;i<=n;i++)

        for (j=1;j<=m;j++)

            if (a[i][j] == 1)

                Q[sf++] = {i,j};

    lee();

    cout << maxim-1;

    return 0;

}



void lee()

{

    while (in < sf)

    {

        auto aux = Q[in++];

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

        {

            int l9 = aux.first+dx[i];

            int c9 = aux.second+dy[i];

            if (!a[l9][c9])

            {

                a[l9][c9] = a[aux.first][aux.second]+1;

                Q[sf++] = {l9,c9};

                if (a[l9][c9] > maxim)

                    maxim = a[l9][c9];

            }

        }

    }

}