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

#include <cstdio>

#include <queue>

#include <cstring>

using namespace std;



//char s[1003][1003];

int vis[1003][1003];

struct node

{

    int x;int y;

};



int main()

{

    int h,w;

    cin>>h>>w;

    queue<node> q;

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

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

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

            char s;cin>>s;

            if(s=='#'){

                node a;a.x=i;a.y=j;

                q.push(a);

                vis[i][j]=1;

            }

        }

    }

    while(!q.empty()){

        node a;a=q.front();q.pop();

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

            vis[a.x-1][a.y]=vis[a.x][a.y]+1;

            node b;b.x=a.x-1;b.y=a.y;

            q.push(b);

        }

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

            vis[a.x][a.y-1]=vis[a.x][a.y]+1;

            node b;b.x=a.x;b.y=a.y-1;

            q.push(b);

        }

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

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

            node b;b.x=a.x+1;b.y=a.y;

            q.push(b);

        }

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

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

            node b;b.x=a.x;b.y=a.y+1;

            q.push(b);

        }

    }

    int ans=0;

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

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

            ans=max(ans,vis[i][j]);

            //cout<<vis[i][j];

        }

        //cout<<endl;

    }

    cout<<ans-1<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.128409611715892x):
#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;

}