#include "bits/stdc++.h"

using ll = long long;

using namespace std;
#define int ll

// 0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
// a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
// a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
// a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)                                                              \
	sort(all(v));                                                              \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
	type x;                                                                    \
	cin >> x
#define YES(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "YES" << endl;                                                 \
	} else {                                                                   \
		cout << "NO" << endl;                                                  \
	}
#define Yes(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "Yes" << endl;                                                 \
	} else {                                                                   \
		cout << "No" << endl;                                                  \
	}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N)                                                             \
	do {                                                                       \
		v.RS(N);                                                               \
		rep (i, N)                                                             \
			cin >> v[i];                                                       \
	} while (0);

#define RCINV(v, N)                                                            \
	do {                                                                       \
		v.RS(N);                                                               \
		rrep (i, N)                                                            \
			cin >> v[i];                                                       \
	} while (0);
#define MOD 1000000007

template <class T> inline T GET()
{
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

template <class T, char d = '\n'> struct Vector
{
	vector<T> v;
	Vector(int sz) : v(sz) {}
	Vector(int sz, T t) : v(sz, t) {}
	Vector() : v(0) {}
	Vector(vector<T> t) : v(t) {}
	inline auto begin() { return v.begin(); }
	inline auto end() { return v.end(); }
	inline auto rbegin() { return v.rbegin(); }
	inline auto rend() { return v.rend(); }
	inline int size() { return v.size(); }
	inline auto resize(int sz) { v.resize(sz); }
	inline auto resize(int sz, T t) { v.resize(sz, t); }
	inline auto empty() { v.empty(); }
	inline auto reserve(int sz) { v.reserve(sz); }
	inline auto push_back(T t) { v.push_back(t); }
	inline auto pop_back() { v.pop_back(); }
	inline auto assign(int sz, const T &t) { v.assign(sz, t); }
	inline auto &front() { return v.front(); }
	inline auto &back() { return v.back(); }
	inline auto insert(const typename vector<T>::iterator p, const T &t)
	{
		v.insert(p, t);
	}
	inline auto insert(const typename vector<T>::iterator p,
					   typename vector<T>::iterator f,
					   typename vector<T>::iterator l)
	{
		v.insert(p, f, l);
	}

	inline auto erase(const typename vector<T>::iterator p) { v.erase(p); }
	inline auto erase(const typename vector<T>::iterator f,
					  const typename vector<T>::iterator s)
	{
		v.erase(f, s);
	}
	inline auto emplace_back(T &t) { v.emplace_back(t); }
	inline auto swap(Vector<T> &f) { v.swap(f.v); }
	inline auto clear() { v.clear(); }
	inline auto &operator[](size_t pos) { return v[pos]; }
	inline auto operator<(const Vector &a) { return v < a.v; }
	inline auto operator>(const Vector &a) { return a < (*this); }
	inline auto operator>=(const Vector &a) { return !((*this) < a); }
	inline auto operator<=(const Vector &a) { return !(a < (*this)); }
	inline auto operator==(const Vector &a)
	{
		return !(a < (*this)) && !((*this) < a);
	}

	inline friend istream &operator>>(istream &lhs, Vector &rhs)
	{
		for (auto &x : rhs) lhs >> x;
		return lhs;
	}
	inline friend ostream &operator<<(ostream &lhs, Vector &rhs)
	{
		for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << d;
		if (rhs.size()) lhs << rhs.back();
		return lhs;
	}
	inline auto make_accumulate_sum(T init)
	{
		Vector<T> res;
		res.push_back(init);
		for (auto x : v) {
			auto y = res.back();
			res.push_back(y + x);
		}
		return res;
	}
};

const int INF = 1e9;

template<class COST_T>
struct Edge_Cost {
	int from;
	int to;
	COST_T cost;
	Edge_Cost(int from_, int to_, COST_T cost_) : from(from_), to(to_), cost(cost_) {}
	Edge_Cost(void) : from(0), to(0), cost(0) {}
	inline bool operator<(const Edge_Cost a) const {
		return cost < a.cost;
	}
	inline bool operator>(const Edge_Cost a) const {
		return a < (*this);
	}
};
using edge = Edge_Cost<int>;

template<class Edge>
struct Edges_List {
	vector<vector<Edge>> E;
	int n;
	void init(int sz) {
		n = sz;
		E.resize(sz);
	}
	void add_edge(Edge e) {
		E[e.from].emplace_back(e);
	}
	vector<Edge>& operator[](int x) {
		return E[x];
	}
	size_t size() {
		return n;
	}
};
using edges = Edges_List<edge>;
/*
	Depends on 
		- Edge_Cost or Edge_Cap_Rev
*/

template<template<class> class Edges, template<class> class Edge, class COST_T>
void Dijkstra(int s, Edges<Edge<COST_T>>& v, COST_T INF_VALUE, vector<COST_T>& res)
{
	res.assign(v.size(), INF_VALUE);
	using edge = Edge<COST_T>;
	priority_queue<edge, vector<edge>, greater<edge>> q;
	q.emplace(s, s, 0);
	while (!q.empty()) {
		auto a = q.top();
		q.pop();
		if (a.cost >= res[a.to]) continue;
		res[a.to] = a.cost;
		for (auto& p : v[a.to]) {
			if (a.cost + p.cost < res[p.to]) q.emplace(a.to, p.to, a.cost + p.cost);
		}
	}
}


/*
	Depends on
		- Edge_Cost
		- Edges_List or Edges_Matrix
*/

void init()
{
	int H, W;
	cin >> H >> W;
	vector<int> res(H * W, INF);
	vector<vector<int>> re(H, vector<int>(W, -1));
	priority_queue<edge, vector<edge>, greater<edge>> q;
	rep(i, H) {
		rep(j, W) {
			char c;
			cin >> c;
			if (c == '#') q.emplace(-1, i * W + j, 0);
		}
	}
	int r = 0;
	while (q.size()) {
		auto a = q.top();
		q.pop();
		if (a.cost >= res[a.to]) continue;
		res[a.to] = a.cost;
		chmax(r, a.cost);
		//cout << a.to % W << " " << a.to / W << " " << a.cost << endl;
		re[a.to / W][a.to % W] = a.cost;
		int d[] = {-W, W, 1, -1};
		rep(i, 4) {
			int n = d[i] + a.to;
			if (n < 0 || n >= H * W) continue;
			if (d[i] == 1 && n % W == 0) continue;
			if (d[i] == -1 && n % W == W - 1) continue;
			if (a.cost + 1 < res[n]) {
				q.emplace(-1, n, a.cost + 1);
			}
		}
	}
	cout << r << endl;
}

void solve()
{
}


Measured memory_bytes: 65768