#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }
void grid_search(vector<string>&grid) {
	int H = grid.size();
	int W = grid[0].size();
	enum { BLOCK, OK };
	assert(0 < H and 0 < W);
	auto inrange = [&](int x, int y) {return 0 <= x and x < H and 0 <= y and y < W; };
	int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
	vector<vector<int>>dist(H, vector<int>(W, INF));
	queue<pii>q;
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (grid[i][j] == '#') {
				dist[i][j] = 0;
				q.emplace(i, j);
			}
		}
	}
	while (q.size()) {
		pii v = q.front();
		q.pop();
		for (int k = 0; k < 4; k++) {
			pii u(v.first + dx[k], v.second + dy[k]);
			if (not inrange(u.first, u.second))continue;
			if (dist[u.first][u.second] != INF)continue;
			if (1) {
				dist[u.first][u.second] = dist[v.first][v.second] + 1;
				q.push(u);
			}
		}
	}
	int ans = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			chmax(ans, dist[i][j]);
		}
	}
	cout << ans << endl;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int H, W; cin >> H >> W;
	vector<string>v(H); rep(i, 0, H) { cin >> v[i]; }
	grid_search(v);

	//auto check = [&](vector<string>&x) {
	//	int cnt = 0;
	//	rep(i, 0, H) {
	//		rep(j, 0, W) {
	//			if (x[i][j] == '#') {
	//				cnt++;
	//			}
	//		}
	//	}
	//	return cnt == H * W;
	//};
	//int ans = 0;
	//int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
	//auto inrange = [&](int x, int y) { return 0 <= x and x < H and 0 <= y and y < W; };
	//while (1) {
	//	if (check(v)) {
	//		break;
	//	}
	//	queue<pii>q;
	//	auto vv = v;
	//	rep(i, 0, H) {
	//		rep(j, 0, W) {
	//			if (v[i][j] == '#') {
	//				rep(k, 0, 4) {
	//					int x = i + dx[k], y = j + dy[k];
	//					if (not inrange(x, y)) {
	//						continue;
	//					}
	//					vv[x][y] = '#';
	//				}
	//			}
	//		}
	//	}
	//	swap(v, vv);
	//	ans++;
	//}
	//cout << ans << endl;

	return 0;
}


Measured memory_bytes: 25524