// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

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

#define FOR(i, a, b) for (ll i = a; i < b; i++)

#define len(v) ll(v.size())



//vector書き出し

template <class T>

void cout_vec(const vector<T> &vec1){

  rep(i,len(vec1)){

    cout<<vec1[i]<<' ';

  }

  cout<<'\n';

}



typedef pair<int,int> P;

const ll mod=1e9+7;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int h,w;

    cin>>h>>w;

    vector<vector<char> > a(1010,vector<char>(1010));

    vector<int> dx={1,-1,0,0},dy={0,0,1,-1};

    vector<vector<int> > d(1010,vector<int>(1010,-1));

    queue<P> que;

    FOR(i,1,h+1){

      FOR(j,1,w+1){

        cin>>a[i][j];

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

          que.push({i,j});

          d[i][j]=0;

        }

      }

    }

    while(!que.empty()){

      P p=que.front();

      que.pop();

      rep(i,4){

        int nx=p.first+dx[i],ny=p.second+dy[i];

        if(1<=nx && nx<=h && 1<=ny && ny<=w && d[nx][ny]==-1){

          d[nx][ny]=d[p.first][p.second]+1;

          que.push({nx,ny});

        }

      }

    }

    int ans=0;

    FOR(i,1,h+1){

      FOR(j,1,w+1){

        if(ans<d[i][j]) ans=d[i][j];

      }

    }

    cout<<ans<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 6.40827491845332x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<ll,ll> P;

typedef pair<int,int> Pi;

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

#define FOR(i,a,b) for(ll i=a;i<b;i++)

#define fi first

#define se second



template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}

template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}

template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}

template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}



const ll mod=1e9+7;

const ll inf=1e17;

const int INF=1e9;

const double PI=acos(-1);

const double EPS=1e-10;



int main(){

	cin.tie(0);ios::sync_with_stdio(false);

	int h,w;

	cin>>h>>w;

	vector<string> a(h);

	queue<Pi> que;

	vector<vector<int>> dist(h,vector<int>(w,INF));

	vector<int> dx={1,-1,0,0},dy={0,0,1,-1};

	rep(i,h){

		cin>>a[i];

		rep(j,w){

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

				que.push(Pi(i,j));

				dist[i][j]=0;

			}

		}

	}

	int ans=0;

	while(!que.empty()){

		auto now=que.front();

		que.pop();

		rep(i,4){

			int nx=now.fi+dx[i],ny=now.se+dy[i];

			if(0<=nx && nx<h && 0<=ny && ny<w){

				if(dist[nx][ny]==INF){

					dist[nx][ny]=dist[now.fi][now.se]+1;

					chmax(ans,dist[nx][ny]);

					que.push(Pi(nx,ny));

				}

			}

		}

	}

	cout<<ans<<endl;

}