/*************

      /\
     /  \
    / AC \
   /      \

*************/


//#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

/*** TEMPLATE START ***/
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795028841971693993751
#endif
using namespace std;

typedef vector<string> vs;
typedef complex<double> pnt;

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


#define SZ(x) ((ll) (x).size())

#define pb push_back
#define mp make_pair
#define eb emplace_back

#define fi first
#define se second


typedef tuple<int, int, int> t3;

typedef double db;
typedef long double ldb;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;

int IT_MAX = 1 << 17;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;


mt19937 mrand(random_device{}());

int rnd(int x) { return mrand() % x; }


template<class T>
void splitstr(const string &s, vector<T> &out) {
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
inline T pow_mod(T p, T e, T M) {
    T ret = 1;
    for (; e > 0; e >>= 1) {
        if (e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T) ret;
}

template<class T>
inline T modinverse(T a, T M) { return pow_mod(a, M - 2, M); }

template<class T>
inline T lcm(T a, T b) {
    a = abs(a);
    b = abs(b);
    return (a / gcd(a, b)) * b;
}

template<class T, class X>
inline bool getbit(T a, X i) {
    T t = 1;
    return ((a & (t << i)) > 0);
}

template<class T, class X>
inline T setbit(T a, X i) {
    T t = 1;
    return (a | (t << i));
}

template<class T, class X>
inline T resetbit(T a, X i) {
    T t = 1;
    return (a & (~(t << i)));
}


//#define endl '\n';

/*** TEMPLATE ENDS ***/



//const ll mod = 1000000007;


/*

 */

const int limit = 1002;
//int A[limit];
//int B[limit];
//int n1=0;
//char C[limit];
//char target[5] = "ACTG";
//const ll mod = 1000000007;

int S[limit];
int E[limit];
int L[limit];
//double R[limit];

//int B[limit];
char C[limit][limit];
int nb[4][2] = {{-1, 0},
                {1,  0},
                {0,  1},
                {0,  -1}};

void solve() {
//int n, m,h;
    //       scanf("%d %d %d", &n, &m,&h);
//int n,k,a,b;
//    scanf("%d %d", &n,&k);

    //    scanf("%d %d",&a,&b);

    // int ntest;
    // scanf("%d", &ntest);
    int ntest = 1;

    for (int itest = 1; itest <= ntest; ++itest) {
        int n, s, x, y, m;
        scanf("%d", &n);
        scanf("%d", &m);


        for (int i = 0; i < n; ++i) {
            scanf("%s", C[i]);
        }

        vector<pair<int, int>> q(0);
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j) {
                if (C[i][j] == '#')
                    q.push_back({i, j});
            }
        int step = 0;
        while (!q.empty()) {
            vector<pair<int, int>> q2(0);
            for (auto &&a :q) {
                for (int kk = 0; kk < 4; ++kk) {
                    int i = a.first+nb[kk][0];
                    int j = a.second+nb[kk][1];
                    if(i>=0 && j>=0 && i<n&&j<m&&C[i][j]=='.'){
                        C[i][j]='#';
                        q2.push_back({i, j});
                    }
                }
            }
           if (!q2.empty())
               step++;
            q=q2;


        }
        printf("%d\n",step);
    }


    // scanf("%s",C);




    // printf("%d\n",n2);

    // printf("%lld %lld\n",target/maxg,target/ming);
    // printf("\n");



    // printf("%d\n", left);
    //printf("%d\n", res);

    //ll a,b;
    // scanf("%lld %lld", &a,&b);
    // ll res = get_sum(b) - get_sum(a-1);
    //  res = (res%mod+mod)%mod;


    //  printf("%lld\n", res);


}


int main() {
// ios::sync_with_stdio(false);
//    cin.tie(NULL);
//    clock_t beg = clock();

    solve();


    //   clock_t end = clock();
//fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
    return 0;
}



Measured memory_bytes: 14824