#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<sstream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<stack>
#include<functional>
#include<utility>
#include<numeric>
#include<bitset>
#include<iterator>
#define INF (int)1e9
#define MOD 1000000007
#define tr(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define debug(x) cout<<#x" = "<<(x)<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz size
#define ll long long
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MEM(a, b) memset(a, (b), sizeof(a))
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?"\n":" ")
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?"\n":" ")
#define PRE(i, m, n, in) for(int (i)=(m);(i)<(n);i+=in)
#define RFOR(i, n) for(int i=n ; i>=0 ; i--)
#define RPRE(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define ERS(A, P) A.erase(A.begin() + P)
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define toint(a) atoi(a.c_str())
using namespace std;
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector<string> VS;
typedef vector <VS> VSS;
typedef vector <II> VII;
typedef vector <LL> VLL;
typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VII> VVII;
typedef vector <VLL> VVLL;
typedef map<int,int> MPII;
typedef map<ll,ll> MPLL;
typedef map<string, int>MPSI;
typedef map<string, ll>MPSL;
typedef map<int, string>MPIS;
typedef map<ll, string> MPLS;
typedef map<string, string> MPSS;
typedef set<int> SETI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  int h, w; cin >> h >> w; // #: black, .: white
  VS a(h);
  queue <II> pq;
  int num_black = 0;
  FOR(i, h) {
    cin >> a[i];
    FOR(j, w) {
      if(a[i][j] == '#') {
        pq.push({i, j}); num_black += 1;
        // cout << pq.front().fi << " " << pq.front().se << "\n";
      }
    }
  }
  int res = 0;
  while(num_black < h*w) {
    int num = pq.size(); int it = 0;
    while(it < num) {
      II c = pq.front();
      pq.pop();
      if(c.fi - 1 >= 0 && a[c.fi - 1][c.se] == '.') {
        num_black += 1;
        a[c.fi - 1][c.se] = '#';
        pq.push({c.fi - 1, c.se});
      }
      if(c.fi + 1 < h && a[c.fi + 1][c.se] == '.') {
        num_black += 1;
        a[c.fi + 1][c.se] = '#';
        pq.push({c.fi + 1, c.se});
      }
      if(c.se - 1 >= 0 && a[c.fi][c.se  - 1] == '.') {
        num_black += 1;
        a[c.fi][c.se  - 1] = '#';
        pq.push({c.fi, c.se  - 1});
      }
      if(c.se + 1 < w && a[c.fi][c.se + 1] == '.') {
        num_black += 1;
        a[c.fi][c.se + 1] = '#';
        pq.push({c.fi, c.se + 1});
      }
      it += 1;
    }
    res += 1;
  }
  std::cout << res << '\n';
  return 0;
}


Measured memory_bytes: 9488