#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll visited[1001][1001];
bool check(ll x,ll y,ll n,ll m)
{
    if(x>=0 and y>=0 and x<n and y<m)
        return true;
    return false;
}
signed main()
{
    fast;
    ll n,m;
    cin>>n>>m;
    char arr[n][m];
    ll i,j;
    queue < ll > q;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>arr[i][j];
            visited[i][j] = 1e18;
            if(arr[i][j]=='#')
                visited[i][j] = 0,q.push(i*m+j);
        }
    }
    while(!q.empty())
    {
        ll x = q.front();
        q.pop();
        ll dirx[4] = {0,0,1,-1};
        ll diry[4] = {1,-1,0,0};
        for(i=0;i<4;i++)
        {
            for(j=0;j<4;j++)
            {
                if(!dirx[i] and !diry[j])
                    continue;
                if(dirx[i] and diry[j])
                    continue;
                if(check(x/m+dirx[i],x%m+diry[j],n,m) and visited[x/m+dirx[i]][x%m+diry[j]]==1e18)
                {
                    visited[x/m+dirx[i]][x%m+diry[j]] = visited[x/m][x%m]+1;
                    q.push((x/m+dirx[i])*m+x%m+diry[j]);
                }

            }
        }
    }
    ll ans= 0;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            ans = max(ans,visited[i][j]);
    cout<<ans;
    
}


Measured memory_bytes: 17296