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

#define ALL(x) x.begin(), x.end()

#define LEN(x) (int)x.size()

#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)

using namespace std;

typedef int64_t i64;

typedef pair<int,int> pii;

template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}

template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;



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

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





int H, W;

char mat[1005][1005];

int dist[1005][1005];



signed main()

{

  cin >> H >> W;

  for (int i = 0; i < H; ++i) {

    cin >> mat[i];

  }



  queue<pii> que;

  memset(dist, INF, sizeof(dist));



  for (int i = 0; i < H; ++i) {

    for (int j = 0; j < W; ++j) {

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

        que.emplace(i, j);

        dist[i][j] = 0;

      }

    }

  }



  int ans = 0;



  while(!que.empty()) {

    const auto now = que.front(); que.pop();



    for (int i = 0; i < 4; ++i) {

      const int ny = now.first + dy[i];

      const int nx = now.second + dx[i];

      if (ny < 0 || nx < 0 || ny >= H || nx >= W || dist[ny][nx] < INF) continue;

      const int nc = dist[now.first][now.second] + 1;

      mat[ny][nx] = '#';

      chmin(dist[ny][nx], nc);

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

      que.emplace(ny, nx);

    }

  }



  cout << ans << endl;



  return 0;

}




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

// Begin Header {{{

#define let             const auto

#define all(x)          (x).begin(), (x).end()

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

#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)

#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)

#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)

#define lowerBound(...)                 lowerBound_(__VA_ARGS__)

#define upperBound(...)                 upperBound_(__VA_ARGS__)

#define lowerBound_(begin, end, ...)    (lower_bound((begin), (end), __VA_ARGS__) - (begin))

#define upperBound_(begin, end, ...)    (upper_bound((begin), (end), __VA_ARGS__) - (begin))



#ifdef DBG

#define trace(...) trace_g(#__VA_ARGS__, __VA_ARGS__)

#else

#define trace(...)

#endif



using namespace std;

using i64 = int_fast64_t;

using pii = pair<i64, i64>;

template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}

template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}

inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }

inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }

inline i64  sqr(i64 n)              { return n * n; }

inline string to_string(char c)     { return string(1, c); }

inline bool   isRangeIn(i64 a, i64 low, i64 high) { return (low <= a && a <= high); }

constexpr int INF  = 0x3f3f3f3f;

constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;



template<class T>

vector<T> makeVec(size_t sz) { return vector<T>(sz); }



template<class T, class... Args>

auto makeVec(size_t sz, Args... args) {

    return vector<decltype(makeVec<T>(args...))>(sz, makeVec<T>(args...));

}



template<class T>

inline void input(T &x) { cin >> x; }



template<class Head, class... Tail>

inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }



inline void print() { cout << "\n"; }



template<class Head, class... Tail>

inline void print(Head &&head, Tail&&... tail) {

    cout << head;

    if (sizeof...(tail)) cout << ' ';

    print(forward<Tail>(tail)...);

}



template<class T>

ostream& operator<< (ostream &out, const vector<T> &vec) {

    static constexpr const char *delim[] = { " ", "" };

    for (const auto &e : vec) out << e << delim[&e == &vec.back()];

    return out;

}



template<class T>

ostream& operator<< (ostream &out, const vector<vector<T>> &mat) {

    static constexpr const char *tail[] = { "\n", "" };

    for (const auto &row : mat) out << row << tail[&row == &mat.back()];

    return out;

}



template <class T>

void trace_g(const char *s, T&& x) {

    clog << '{';

    while(*s != '\0') clog << *(s++);

    clog << ":" << setw(3) << x << '}' << endl;

}



template <class Head, class... Tail>

void trace_g(const char *s, Head&& head, Tail&&... tail) {

    clog << '{';

    while(*s != ',') clog << *(s++);

    clog << ":" << setw(3) << head << "}, ";

    for (++s; !isgraph(*s); ++s);

    trace_g(s, std::forward<Tail>(tail)...);

}

// }}} End Header



auto gridBFS(const vector<string> &grid, const vector<pair<int,int>> &starts, const string &walls)

    -> vector<vector<int>>

{

    static constexpr array<int, 4> dy {1, 0, -1, 0};

    static constexpr array<int, 4> dx {0, 1, 0, -1};

    static_assert(dy.size() == dx.size(), "Length of dy[], dx[] is different!");



    const int H = grid.size();

    const int W = grid[0].size();

    vector<vector<int>> dist(H, vector<int>(W, -1));

    queue<pair<int,int>> que;



    for (const auto &e : starts) {

        dist[e.first][e.second] = 0;

        que.emplace(e.first, e.second);

    }



    while(!que.empty()) {

        const int curY = que.front().first;

        const int curX = que.front().second;

        que.pop();

        for (int i = 0; i < dy.size(); ++i) {

            const int ny = curY + dy[i];

            const int nx = curX + dx[i];

            if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;

            if (dist[ny][nx] != -1) continue;

            if (walls.find(grid[ny][nx]) != string::npos) continue;

            dist[ny][nx] = dist[curY][curX] + 1;

            que.emplace(ny, nx);

        }

    }



    return dist;

}



signed main()

{

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



    var(int, H, W);

    vector<string> mat(H);

    vector<pair<int,int>> starts;



    rep(i, H) {

        input(mat[i]);

        rep(j, W) {

            if (mat[i][j] == '#') starts.emplace_back(i, j);

        }

    }



    const auto dist = gridBFS(mat, starts, "#");



    int res = 0;

    rep(i, H) rep(j, W) chmax(res, dist[i][j]);



    print(res);



    return 0;

}