#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <iostream>
#include <math.h>
#include <cmath>
#include <iterator>
//#include <unordered_map>
//#include <unordered_set>
#include <functional>
#include <queue>
#include <iomanip>
#include <istream>
#include <map>
#include <list>
#include <stack>
#include <numeric>
#include <ostream>
#include <set>
#include <cassert>
#include <deque>
#include <sstream>
#include <string>
#include <utility>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <random>

using namespace std;

#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define fi first
#define se second
#define REP(i, a, n) for (int (i)=(a);(i)<(n);(i)++)
#define PER(i, a, n) for (int (i)=(n)-1;(i)>=(a);(i)--)

typedef long double 	ld;
typedef long long 		ll;
typedef vector<int> 	VI;
typedef pair<int, int>	PII;
typedef pair<ll, ll> 	PLL;
typedef vector<ll>		VL;
typedef vector<PLL> 	VPL;
typedef vector<PII> 	VPI;

#ifndef ONLINE_JUDGE
#define dbb(x)		{ cerr << #x << " = " << x << "\t";      }
#define db(x)		{ dbb(x); cerr << endl; }
#define db2(x,y)	{ dbb(x); dbb(y); cerr << endl; }
#define db3(x,y,z)	{ dbb(x); dbb(y); dbb(z); cerr << endl; }
#else
#define dbb(x)		;
#define db(x)		;
#define db2(x,y)	;
#define db3(x,y,z)	;
#endif



const ll  MOD = 1000000007ll;

ll powmod(ll a, ll b) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a%MOD; a = a * a%MOD; }return res; }
template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a < (t1)b) { a = (t1)b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a > (t1)b) { a = (t1)b; return true; } else return false; }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T> inline T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> inline T sqr(T a) { return a * a; }

int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dkx[] = { -1, -1, 1, 1, -2, -2, 2, 2 };
int dky[] = { -2, 2, -2, 2, -1,  1,-1, 1 };

const int INF = 1000000404;
const ll  LINF = 4000000000000000404ll;
const ld  PI = 3.14159265358979323846;
const ld  EPS = 1e-9;

int SQ = 318;
int timer = 0;

#define N 1010
int d[N][N];
char a[N][N];
void solve() {
	int n, m;
	cin >> n >> m;
	queue<int> qx;
	queue<int> qy;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
			d[i][j] = INF;
			if (a[i][j] == '#') {
				d[i][j] = 0;
				qx.push(i);
				qy.push(j);
			}		
		}
	}

	while (!qx.empty()) {
		int x = qx.front(); qx.pop();
		int y = qy.front(); qy.pop();

		for (int i = 0; i < 4; i++) {
			int X = x + dx[i];
			int Y = y + dy[i];

			if (X >= 1 && X <= n && Y >= 1 && Y <= m) {
				if (d[X][Y] > d[x][y] + 1) {
					d[X][Y] = d[x][y] + 1;
					qx.push(X);
					qy.push(Y);
				}
			}
		}
	}
	int minn = 0;
	REP(i, 1, n + 1) {
		REP(j, 1, m + 1) {
			upmax(minn, d[i][j]);
		}
	}
	cout << minn << endl;



}

int main()
{
#ifndef ONLINE_JUDGE	
	///freopen("input.txt", "r", stdin);
	///freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int t = 1;
	//cin >> t;

	while (t--) {

		solve();

	}

	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 13440