#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

struct Point{
  int x, y;
  Point(): x(0), y(0){}
  Point(int x, int y): x(x), y(y){}
  Point& operator+=(const Point &a){this->x+=a.x; this->y+=a.y; return *this;}
  Point& operator-=(const Point &a){this->x-=a.x; this->y-=a.y; return *this;}
};

Point operator+(const Point &a, const Point &b){return Point(a.x+b.x, a.y+b.y);}
Point operator-(const Point &a, const Point &b){return Point(a.x-b.x, a.y-b.y);}
bool operator==(const Point &a, const Point &b){return a.x==b.x and a.y==b.y;}
bool operator!=(const Point &a, const Point &b){return !(a==b);}

ostream& operator<<(ostream &os, const Point &a){
  os << "(" << a.x << "," << a.y << ")";
  return os;
}

const vector<Point> dir4 = {Point(0,1), Point(0,-1), Point(1,0), Point(-1,0)};
const vector<Point> dir8 = {Point(-1,-1), Point(-1,0), Point(-1,1), Point(1,-1), Point(1,0), Point(1,1), Point(0,-1), Point(0,1)};



template <typename T>
void bfs_grid(const vector<T> &field, int H, int W,
              const vector<Point> &start_points, const vector<Point> &dir,
              const function<bool(Point)> &check_passable,
              vector<vector<int>> &dist
              ){
  
  dist = vector<vector<int>>(H, vector<int>(W, -1));

  vector<vector<bool>> visited(H, vector<bool>(W));

  queue<Point> q;
  for(auto &p : start_points){
    dist[p.x][p.y] = 0;
    q.push(p);
  }
  
  while(not q.empty()){
    auto cur = q.front(); q.pop();

    if(visited[cur.x][cur.y]) continue;
    visited[cur.x][cur.y] = true;

    for(auto &d : dir){
      auto nxt = cur + d;

      if(nxt.x < 0 or nxt.x >= H or nxt.y < 0 or nxt.y >= W or not check_passable(nxt)) continue;

      if(dist[nxt.x][nxt.y] == -1){
        dist[nxt.x][nxt.y] = dist[cur.x][cur.y] + 1;
      }else{
        chmin(dist[nxt.x][nxt.y], dist[cur.x][cur.y] + 1);
      }
      q.push(nxt);
    }
  }
}







int main(){
  int H,W;

  while(cin >> H >> W){
    vector<string> S(H); cin >> S;

    vector<Point> st;
    REP(i,H){
      REP(j,W){
        if(S[i][j] == '#'){
          st.push_back(Point(i,j));
        }
      }
    }

    vector<vector<int>> dist;

    auto check = [&](const auto &p){return S[p.x][p.y] == '.';};
    bfs_grid(S, H, W, st, dir4, check, dist);

    dump(dist);
    

    int ans = 0;

    REP(i,H) REP(j,W) chmax(ans, dist[i][j]);

    cout << ans << endl;
  }
  

  return 0;
}


Measured memory_bytes: 21480