#include<bits/stdc++.h>
 
using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define all(v) v.begin(),v.end()
#define vll vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

ll gcd(ll a, ll b) { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);        
}

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}

vll graph[1001];
ll h,w;
queue<pll> q1;
void func()
{
    //cout<<a<<b<<endl;
    ll tempans=0;
    vector<pll> v1;
    while(!q1.empty())
    {
        pll top=q1.front();
        ll a=top.ff;
        ll b=top.ss;
        ll val=graph[a][b];
        if(a>0)
        {
            if(graph[a-1][b]==0)
            {
                graph[a-1][b]=val+1;
                q1.push(mp(a-1,b));
            }
            // else if(graph[a-1][b]>val+1)
            // {
            //     graph[a-1][b]=val+1;
            // }

        }
        if(b>0 and graph[a][b-1]==0)
        {
            graph[a][b-1]=val+1;
            q1.push(mp(a,b-1));
            //tempans=max(tempans,1+func(a,b-1));
        }
        // else if(graph[a][b-1]>val+1)
        //     {
        //         graph[a][b-1]=val+1;
        //     }
        if(a<h-1 and graph[a+1][b]==0)
        {
            graph[a+1][b]=val+1;
            q1.push(mp(a+1,b));
            //tempans=max(tempans,1+func(a+1,b));
        }
        // else if(graph[a+1][b]>val+1)
        //     {
        //         graph[a+1][b]=val+1;
        //     }
        if(b<w-1 and graph[a][b+1]==0)
        {
            graph[a][b+1]=val+1;
            q1.push(mp(a,b+1));
            //tempans=max(tempans,1+func(a,b+1));
        }
        q1.pop();
    }
}
signed main() 
{
    //fast_cin();
    cin>>h>>w;
    For(i,0,h)
    {
        string s;
        cin>>s;
        For(j,0,w)
        {
            if(s[j]=='#')
                graph[i].pb(1);
            else
                graph[i].pb(0);
        }
    }
    ll ans=0;
    vector<pll> v1;
    For(i,0,h)
    {
        For(j,0,w)
        {
            if(graph[i][j]==1)
                q1.push(mp(i,j));
        }
    }
    func();
    For(i,0,h)
    {
        For(j,0,w)
        {
            ans=max(ans,graph[i][j]);
        }
    }
    cout<<ans-1<<endl;
    return 0;    
}

Measured memory_bytes: 24628