// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<queue>

#include<map>

#include<math.h>

#include<iomanip>

#include<set>

#include<numeric>

#include<cstring>

#include<cstdio>

#include<functional>

#include<bitset>



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

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define FORR(i, m, n) for(int i = m;i >= n;i--)

#define SORT(v, n) sort(v, v+n);

#define VSORT(v) sort(v.begin(), v.end());

#define REVERSE(v,n) reverse(v,v+n);

#define VREVERSE(v) reverse(v.begin(), v.end());

#define ll long long

#define pb(a) push_back(a)

#define m0(x) memset(x,0,sizeof(x))

#define print(x) cout<<x<<endl;

#define pe(x) cout<<x<<" ";

#define lb(v,n) lower_bound(v.begin(), v.end(), n);

#define ub(v,n) upper_bound(v.begin(), v.end(), n);

#define int long long

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



using namespace std;



const int MAX = 1010000;

const int MOD = (ll)1000000000 + 7;

const ll INF = 1e17;

const double pi = acos(-1);

const double EPS = 1e-10;



int dx[4] = { 0,0,1,-1 };

int dy[4] = { 1,-1,0,0, };

typedef pair<int, int>P;



char maze[1010][1010];

int H, W;

vector<int> bx, by;

vector<int>Bx[3000], By[3000];

signed main() {

	cin >> H >> W;

	REP(i, H) {

		REP(j, W) {

			cin >> maze[i][j];

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

				bx.pb(i); by.pb(j);

				Bx[0].pb(i); By[0].pb(j);

			}

		}

	}

	int ans = 0;

	bool ok = 0;

	while (!ok) {

		ok = true;

		int n = ans;

		//print(ans);

		REP(i, Bx[n].size()) {

			int x = Bx[n][i], y = By[n][i];

			REP(j, 4) {

				int nx = x + dx[j], ny = dy[j] + y;

				if (nx >= 0 && nx < H&&ny >= 0 && ny < W) {

					if (maze[nx][ny] == '.') {

						if(ok) {

							ans++;

							ok = 0;

						}

						maze[nx][ny] = '#';

						Bx[ans].pb(nx); By[ans].pb(ny);

					}

				}

			}

		}

	}

	/*REP(i, H) {

		REP(j, W) {

			cout << maze[i][j];

		}

		cout << endl;

	}*/

	print(ans);

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<queue>

#include<deque>

#include<map>

#include<math.h>

#include<iomanip>

#include<set>

#include<numeric>

#include<cstring>

#include<cstdio>

#include<functional>

#include<bitset>

#include<limits.h>

#include<cassert>

#include <fstream>

#include <time.h>

#include <iterator>





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

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define FORR(i, m, n) for(int i = m;i >= n;i--)

#define SORT(v, n) sort(v, v+n);

#define VSORT(v) sort(v.begin(), v.end());

#define REVERSE(v,n) reverse(v,v+n);

#define VREVERSE(v) reverse(v.begin(), v.end());

#define ll long long

#define pb(a) push_back(a)

#define m0(x) memset(x,0,sizeof(x))

#define print(x) cout<<x<<endl;

#define pe(x) cout<<x<<" ";

#define lb(v,n) lower_bound(v.begin(), v.end(), n);

#define ub(v,n) upper_bound(v.begin(), v.end(), n);

#define int long long

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



using namespace std;



const int MOD = (ll)1000000000 + 7;

const ll INF = 1e17;

const double pi = acos(-1);

const double EPS = 1e-10;

typedef pair<int, int>P;

const int MAX = 200020;

int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };



int H, W;

char A[1010][1010];

queue<P>que;

int ans = 0;

void BFS(queue<P> que) {

	queue<P>que2;

	bool found = 0;

	while (!que.empty()) {

		P p = que.front();

		que.pop();

		int x = p.first, y = p.second;

		

		REP(i, 4) {

			int nx = x + dx[i], ny = y + dy[i];

			if (nx >= 0 && nx < H&&ny >= 0 && ny < W) {

				if (A[nx][ny] == '.') {

					found = true;

					que2.push({ nx,ny });

					A[nx][ny] = '#';

				}

			}

		}

		

	}

	if (found)ans++;

	else return;

	BFS(que2);

}

void solve() {

	cin >> H >> W;

	REP(i, H) {

		REP(j, W) {

			cin >> A[i][j];

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

				que.push({ i,j });

			}

		}

	}

	BFS(que);

	print(ans);

}



signed main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	solve();

}


// Fastest known solution for this problem: