#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}

bool b[100010]={false};
void pri()
{ b[1]=true;
  b[2]=true;
  b[0]=true;
  rep(i,2,100010)
  {
    for(int j=i+i;j<100010;j+=i)b[j]=true;
  }
}

int solve( ){

int r,c;
cin>>r>>c;
vii v,v1;
int a[r][c];
rep(i,0,r)
{
  rep(j,0,c)
  {
    char c;
    cin>>c;
    if(c=='.')a[i][j]=hell;
    else 
      a[i][j]=0;
    if(c=='#'){v.pb({i,j});v1.pb({j,i});}
  }
}
sort(all(v));
sort(all(v1));
int ans=0;
int x=v.size(),y=v1.size();
rep(i,0,r)
{
  rep(j,0,c)
  {
    if(a[i][j]>ans)
    {   
       int l=lower_bound(all(v),make_pair(i,j))-v.begin();
        int mn=abs(i-v[l].FF)+abs(j-v[l].SS);
          
          int l1=lower_bound(all(v1),make_pair(j,i))-v1.begin();
        int mn1=abs(j-v1[l1].FF)+abs(i-v1[l1].SS);
          
        int l2=lower_bound(all(v),make_pair(i+1,j-1))-v.begin();
        int mn2=abs(i-v[l2].FF)+abs(j-v[l2].SS);
         
          int l3=lower_bound(all(v1),make_pair(j+1,i-1))-v1.begin();
        int mn3=abs(j-v1[l3].FF)+abs(i-v1[l3].SS);
         
         int l4=lower_bound(all(v),make_pair(i-1,j-1))-v.begin();
        int mn4=abs(i-v[l4].FF)+abs(j-v[l4].SS);
        
          int l5=lower_bound(all(v1),make_pair(j-1,i-1))-v1.begin();
        int mn5=abs(j-v1[l5].FF)+abs(i-v1[l5].SS);
          

        rep(k,0,500)
        { if(mn<ans)break;
          if(mn1<ans)break;
          if(mn2<ans)break;
          if(mn3<ans)break;
          if(mn4<ans)break;
          if(mn5<ans)break;

          if(l-k>=0)mn=min(mn,abs(v[l-k].FF-i)+abs(v[l-k].SS-j));
          if(l+k<x)mn=min(mn,abs(v[l+k].FF-i)+abs(v[l+k].SS-j));
          
          if(l1-k>=0)mn1=min(mn1,abs(v1[l1-k].FF-j)+abs(v1[l1-k].SS-i));
          if(l1+k<y)mn1=min(mn1,abs(v1[l1+k].FF-j)+abs(v1[l1+k].SS-i));
          
          if(l2-k>=0)mn2=min(mn2,abs(v[l2-k].FF-i)+abs(v[l2-k].SS-j));
          if(l2+k<x)mn2=min(mn2,abs(v[l2+k].FF-i)+abs(v[l2+k].SS-j));
         
          if(l3-k>=0)mn3=min(mn3,abs(v1[l3-k].FF-j)+abs(v1[l3-k].SS-i));
          if(l3+k<y)mn3=min(mn3,abs(v1[l3+k].FF-j)+abs(v1[l3+k].SS-i));

             if(l4-k>=0)mn4=min(mn4,abs(v[l4-k].FF-i)+abs(v[l4-k].SS-j));
          if(l4+k<x)mn4=min(mn4,abs(v[l4+k].FF-i)+abs(v[l4+k].SS-j));
         
          if(l5-k>=0)mn5=min(mn5,abs(v1[l5-k].FF-j)+abs(v1[l5-k].SS-i));
          if(l5+k<y)mn5=min(mn5,abs(v1[l5+k].FF-j)+abs(v1[l5+k].SS-i));

        }
        
        ans=max(ans,min(mn,min(mn1,min(mn2,min(mn3,min(mn4,mn5))))));
        a[i][j]=ans;
    }
  }
}


cout<<ans;

return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);

//pri();
  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 // cout << "Processor time taken is "
   // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 39500