// 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.071329205592591x):
#include <bits/stdc++.h>

#define N 1005



using namespace std;



short n, m;

char a[N][N];

bool mark[N][N];



struct Element

{

    short lin, col;

    short nivel;

};



queue < Element > c;



short dl[] = {-1, 0, 1,  0};

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



bool inline Verif(Element v)

{

    if(a[v.lin - 1][v.col] == '.' || a[v.lin + 1][v.col] == '.' || a[v.lin][v.col + 1] == '.' || a[v.lin][v.col - 1] == '.')

        return true;



    return false;

}



bool inline Inside(Element p)

{

    if(p.lin >= 1 && p.lin <= n && p.col >= 1 && p.col <= m)

        return true;



    return false;

}



int main()

{

    ios_base::sync_with_stdio(false), cin.tie(0);

    short cnt = 0, i, j;



    cin >> n >> m;



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

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

            cin >> a[i][j];



    short ans = 0;

    bool ok = 0;

    Element p, v;



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

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

        {

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

            {

                c.push(Element{i, j , 1});

                mark[i][j] = 1;

            }

        }



    int nivel = 1;



    while(!c.empty())

    {

        p = c.front();

        c.pop();



        if(Inside(p) == false)

            continue;



        if(Verif(p) == true && p.nivel == nivel)

            ++ans , nivel++;



        a[p.lin - 1][p.col] = a[p.lin + 1][p.col] = a[p.lin][p.col - 1] = a[p.lin][p.col + 1] = '#';



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

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



        for(short t = 0 ; t < 4 ; t++)

        {

            v = {p.lin + dl[t], p.col + dc[t] , nivel};



            if(Inside(v) && !mark[v.lin][v.col])

                c.push(v), mark[v.lin][v.col] = 1 ;

        }

    }



    cout << ans;



    return 0;

}