#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
//struct compare
//{
//  bool operator()(const int& l, const int& r)
//  {
//      return l>r;
//  }
//};

bool cmp(int a, int b)
{
    return a<b;
}
int on(int mask,int st)
{
    return mask|(1<<st);
}
int off(int mask,int st)
{
    return mask&(~(1<<st));
}
bool check(int mask,int st)
{
    return mask&(1<<st);
}
/////////////////////////////////////template sesh/////////////////////////////////////////////////////
///code goes from here




#define MX 200100
ll inf=1e8;
ll MOD=1e9+7;
ll mod=1e9+7;
int arr[2000][2000];
vector<pii>v;
vector<pii>tmp;
int main()
{
//    READ;
//    WRITE;
    int t,tc=1;
    int n,m;
    sf2(n,m);
    char c;
    int tot=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++){
            cin>>c;
            if(c=='#')
            {
                arr[i][j]=1;
                v.pb({i,j});
                tot++;
            }
            else
                arr[i][j]=0;
        }
    }
    int countt=0,x,y;
    while(tot!=(n*m))
    {
        int sz=v.size();
        for(int i=0;i<sz;i++)
        {
            x=v[i].ff;
            y=v[i].sn;
            if(x+1<n)
            {
                if(arr[x+1][y]!=1)
                {
                    arr[x+1][y]=1;
                    tmp.pb({x+1,y});
                    tot++;
                }
            }
            if(x-1>=0)
            {
                if(arr[x-1][y]!=1)
                {
                    arr[x-1][y]=1;
                    tmp.pb({x-1,y});
                    tot++;
                }
            }
            if(y+1<m)
            {
                if(arr[x][y+1]!=1)
                {
                    arr[x][y+1]=1;
                    tmp.pb({x,y+1});
                    tot++;
                }
            }
            if(y-1>=0)
            {
                if(arr[x][y-1]!=1)
                {
                    arr[x][y-1]=1;
                    tmp.pb({x,y-1});
                    tot++;
                }
            }
        }
        v.clear();
        for(int i=0;i<tmp.size();i++)
            v.pb(tmp[i]);
        tmp.clear();
        countt++;
    }
    cout<<countt<<endl;

    return 0;
}


Measured memory_bytes: 23144