#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

queue<pair<int, int>> q;
bool is_rechable(vector<string>& grid, vector<vector<int>>& dis,pair<int,int> &x) {
    int H = grid.size(), W = grid[0].size();
    //cout << x.first << "  " << x.second << endl;
    if (x.first < 0 || x.first >H - 1 || x.second < 0 || x.second > W - 1)return false;
    if (grid[x.first][x.second] == '#') return false;
    if (dis[x.first][x.second])return false;
    return true;
}
/*
void from_dis(vector<string>& grid, vector<vector<int>>& dis, pair<int, int>& x,
    vector<vector<pair<int, int>>>& history, int kyori) {
    //cout << q.front().first<<"  "<<q.front().second <<"  dis="<<kyori<< endl;
    q.pop();
    dis[x.first][x.second] = kyori;
    vector<int> yoko = { 0,1,0,-1 }, tate = { 1,0,-1,0 };

    for (int i = 0; i < 4; i++) {
        pair<int, int> y = make_pair(x.first + tate[i], x.second + yoko[i]);
        if (is_rechable(grid, dis, y)) {
            q.push(y);
            history[y.first][y.second] = x;
        }
    }
    if (q.empty()) return;
    pair<int, int> z = q.front();
    from_dis(grid, dis, z, history,
        dis[history[z.first][z.second]][history[z.first][z.second]] +1);
}
*/
void from_dis(vector<string>& grid, vector<vector<int>>& dis, pair<int, int> x) {
    //cout << q.front().first<<"  "<<q.front().second <<"  dis="<<dis[q.front().first][q.front().second];
    //pair<int,int> x = u.front();
    q.pop();
    vector<int> tate = { -1,0,1,0 }, yoko = { 0,1,0,-1 } ;

    for (int i = 0; i < 4; i++) {
        pair<int, int> y = make_pair(x.first + tate[i], x.second + yoko[i]);
        //cout << "x= " << x.first << "  " << x.second;
        //cout << "   y= "<<y.first << "  " << y.second << endl;
        if (is_rechable(grid, dis, y)) {
            q.push(y);
            dis[y.first][y.second] = dis[x.first][x.second] + 1;
        }
    }
    //cout << "   size=" << q.size() << endl;
    /*
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            printf("dis[%d][%d]=%d\n", i, j, dis[i][j]);
        }
    }
    */
    if (q.empty()) return;
    pair<int, int> z = q.front();
    from_dis(grid, dis, z);
}
int main() {
    int H, W;
    cin >> H >> W;

    vector<string> grid(H);
    vector<vector<int>> dis(H, vector<int>(W));
    vector<vector<pair<int, int>>> history(H, vector<pair<int, int>>(W));
    for (int i = 0; i < H; i++)
        cin >> grid[i];
       
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.')
                continue;          
            q.push(make_pair(i, j));
            history[i][j] = make_pair(i, j);
        }
    }
    /*
    while (!q.empty()) {
        cout << q.front().first << " " << q.front().second << endl;
        q.pop();
    }
    */
    //cout << "start" << endl;
    from_dis(grid, dis, q.front());
    int ans = -1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            //printf("dis[%d][%d]=%d\n", i, j, dis[i][j]);
            ans = max(ans, dis[i][j]);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 185360