#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

struct pos_and_value {
    long long pos;
    long long value;
    pos_and_value(long long pos, long long value) {
        this->pos = pos;
        this->value = value;
    }
};

bool operator>(const pos_and_value& l, const pos_and_value& r) {
    return l.value > r.value;
}

bool is_valid(long long pos, int h, int w) {
    return (pos >= 0 && pos < h*w);
}

int main(){
    int h,w; cin >> h >> w;
    // vector<vector<int> > map;
    vector<int> tmp(w);
    unordered_set<long long> set;
    unordered_map<long long, int> map;
    priority_queue<pos_and_value, vector<pos_and_value>, greater<pos_and_value> > pq;
    rep(i, h) {
        rep(j, w) {
            char c; cin >> c;
            if (c == '.') {
                set.insert(i*w + j);
                map[i*w+j] = 3000;
            } else {
                pq.push(pos_and_value(i*w + j,0));
                map[i*w+j] = 0;
            }
        }
    }
    long long max = 0;
    while(!set.empty()) {
        pos_and_value tmp = pq.top();
        pq.pop();
        // cout << "pop->" << tmp.pos << " " << tmp.value << endl;
        if(is_valid(tmp.pos-1,h,w) && tmp.pos%w != 0) {
            if(set.find(tmp.pos-1) != set.end()) {
                set.erase(tmp.pos-1);
            }
            if(map[tmp.pos-1] > tmp.value + 1){
                map[tmp.pos-1] = tmp.value + 1;
                pq.push(pos_and_value(tmp.pos-1, tmp.value + 1));
                max = tmp.value + 1;
                // cout << "push->" << tmp.pos-1 << " " << tmp.value+1 << endl;
            }
            // pq.push();
        }
        if(is_valid(tmp.pos+1,h,w) && tmp.pos%w != w-1) {
            if(set.find(tmp.pos+1) != set.end()) {
                set.erase(tmp.pos+1);
            }
            if(map[tmp.pos+1] > tmp.value + 1){
                map[tmp.pos+1] = tmp.value + 1;
                pq.push(pos_and_value(tmp.pos+1, tmp.value + 1));
                max = tmp.value + 1;
                // cout << "push->" << tmp.pos+1 << " " << tmp.value+1 << endl;
            }

        }
        if(is_valid(tmp.pos+w,h,w)) {
            if(set.find(tmp.pos+w) != set.end()) {
                set.erase(tmp.pos+w);
            }
            if(map[tmp.pos+w] > tmp.value + 1){
                map[tmp.pos+w] = tmp.value + 1;
                pq.push(pos_and_value(tmp.pos+w, tmp.value + 1));
                max = tmp.value + 1;
                // cout << "push->" << tmp.pos+w << " " << tmp.value+1 << endl;
            }

        }
        if(is_valid(tmp.pos-w,h,w)) {
            if(set.find(tmp.pos-w) != set.end()) {
                set.erase(tmp.pos-w);
            }
            if(map[tmp.pos-w] > tmp.value + 1){
                map[tmp.pos-w] = tmp.value + 1;
                pq.push(pos_and_value(tmp.pos-w, tmp.value + 1));
                max = tmp.value + 1;
                // cout << "push->" << tmp.pos-w << " " << tmp.value+1 << endl;
            }
        }
    }
    // for(auto itr = map.begin(); itr != map.end(); itr++){
    //     cout << itr->second << endl;
    // }
    cout << max << endl;
}



Measured memory_bytes: 84128