// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef int64_t Int;

#define dump(x) cout << (x) << '\n'

Int mod = 1e9+7;

//Int mod = 998244353; 

Int INF = 1e9+7;



int main() {    

    Int h, w;

    cin >> h >> w;

    vector<vector<Int>> a(h + 1, vector<Int>(w + 1, INF));

    char x[1001][1001] = {};

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

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

            cin >> x[i][j];

        }

    }

    vector<vector<Int>> b = a;

    Int cnt = INF;

    bool bl = false;

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

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

            if (bl) cnt++;

            if (x[i][j] == '#') {

                cnt = 0;

                bl = true;

                continue;

            }

            a[i][j] = cnt;

        }

        cnt = INF;

        bl = false;

    }

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

        for (Int j = w - 1; j >= 0; j--) {

            if (bl) cnt++;

            if (x[i][j] == '#') {

                cnt = 0;

                bl = true;

                continue;

            }



            b[i][j] = cnt;

            

        }

        cnt = INF;

        bl = false;

    }

    

    vector<vector<Int>> c = a;

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

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

            if (x[i][j] == '#') {

                c[i][j] = 0;

                continue;

            }

            c[i][j] = min(a[i][j], b[i][j]);

            //cout << c[i][j] << " ";

        }

        //cout << endl;

    }

    vector<vector<Int>> d, e;

    d = e = c;

    

    for (Int i = 0; i < h - 1; i++) {

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

            d[i + 1][j] = min(d[i + 1][j], d[i][j] + 1);

        }

    }

  /*   for (Int i = 0; i < h; i++) {

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

            cout << d[i][j] << " ";

        }

        cout << endl;

    } */

    for (Int i = h - 1; i > 0; i--) {

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

            e[i - 1][j] = min(e[i - 1][j], e[i][j] + 1);

        }

    }

    // dump("PO");

    Int res = 0;

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

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



            if (x[i][j] == '#') continue;

            res = max(res, min(d[i][j], e[i][j]));

        }

    }

    dump(res);

    return 0;  

}

// Faster C++ solution for the same problem (measured speedup: 2.005857367923034x):
#include <bits/stdc++.h>

using namespace std;



#define dump(x) cout << (x) << '\n'

#define Int int64_t

#define fi first

#define se second

#define all(x) (x).begin(), (x).end()

 

Int INF = 1e18;

int inf = 1e9;

Int mod = 1e9+7;



Int d[1001][1001];



int main() {

    Int h, w;

    cin >> h >> w;

    vector<string> s(h);

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

        cin >> s[i];

    }

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

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

            d[i][j] = INF;

        }

    }

    queue<pair<Int, Int>> q;

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

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

            if (s[i][j] == '#') {

                d[i][j] = 0;

                q.push({i, j});

            }

        }

    }

    while (not q.empty()) {

        pair<Int, Int> p = q.front();

        q.pop();

        Int dy[] = {0, 1, 0, -1};

        Int dx[] = {1, 0, -1, 0};

        for (Int i = 0; i < 4; i++) {

            Int ny = p.fi + dy[i];

            Int nx = p.se + dx[i];

            if (ny < 0 or ny == h or nx < 0 or nx == w) continue;

            if (d[ny][nx] > d[p.fi][p.se] + 1) {

                d[ny][nx] = d[p.fi][p.se] + 1;

                q.push({ny, nx});

            }

        }

    }

    Int res = 0;

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

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

            res = max(res, d[i][j]);

        }

    }

    dump(res);

    return 0;

}