#include <bits/stdc++.h>
using namespace std;

int R, C;
int dist[1005][1005], ans;
int sm = 0x3f3f3f3f, bg;

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

int main() {
  freopen("inp", "r", stdin);
  ios_base::sync_with_stdio(0);
  cin >> R >> C;
  queue<pair<int, int>> q;
  char tmp;
  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++){
      cin >> tmp;
      if(tmp == '#'){
        dist[i][j] = 0;
        q.push(make_pair(i, j));
      }else dist[i][j] = 0x3f3f3f;
    }
  }

  while(!q.empty()){
    int ux = q.front().first;
    int uy = q.front().second;
    q.pop();

    for(int i = 0; i < 4; i++){
      int vx = ux + dx[i];
      int vy = uy + dy[i];
      if(vx >= 0 && vx < R && vy >= 0 && vy < C && dist[vx][vy] > dist[ux][uy] + 1){
        q.push(make_pair(vx, vy));
        dist[vx][vy] = dist[ux][uy] + 1;
        ans = max(ans, dist[vx][vy]);
      }

    }
  }
  cout << ans << "\n";
}