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

typedef long long ll;

#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define FOR(i, k, n) for(int64_t i=k;i<n;i++)

#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal> palvec;
typedef map<int, int> iimap;
typedef map<int, bool> ibmap;
typedef map<string, int> simap;
typedef map<string, bool> sbmap;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;




const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll powmod(ll x, ll n){
    ll res=1;
    while(n>0){
        if(n&1) res = res*x%MOD;
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}

ll calc(string s, const bvec &p){
    ll res=0, cnt=1;
    int i = 0;
    for(auto it = s.rbegin(); it != s.rend(); it++){
        ll d = *it -'0';
        res += cnt*d;
        cnt*=10;
        if(p[i]) cnt=1;
        i++;
    }
    

    return res;
}

void rec(int i, int n, bvec &p, string s, ll &ans){
    if(i==n){
        ans+=calc(s, p);
    }
    else{
        p[i]= false;
        rec(i+1, n, p, s, ans);
        p[i] = true;
        rec(i+1, n, p, s, ans);
    }
}

void fill(int i, int j, int c, svec &map, queue<ivec> &q, int &ans){
        if(map[i][j] == '.') {
            map[i][j] = '#';
            q.push({i, j, c+1}); 
            ans=c+1;
        }

}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    svec map(h);
    queue<ivec> q;
    int ans=0;
    REP(i, h){
        string s;        
        cin >> s;
        map[i] = s;
        REP(j, w) if(s[j] == '#') q.push({i,j,0});
    }
    while(!q.empty()){
        ivec p = q.front();
        q.pop();
        int i = p[0], j=p[1], cn=p[2];
        // cout << i << ' ' << j << ' ' << cn << endl;
        int posi=min(i-1,0), posj=j;
        fill(max(i-1, 0), j, cn, map, q, ans);
        fill(min(i+1, h-1), j, cn, map, q, ans);
        fill(i, max(j-1, 0), cn, map, q, ans);
        fill(i, min(j+1, w-1), cn, map, q, ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 56756