#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"def main():\n"
"  from collections import deque\n"
"  s,*c=open(0)\n"
"  h,w=map(int,s.split())\n"
"  f=[-1]*h*w\n"
"  q=deque()\n"
"  a,p=q.append,q.popleft\n"
"  for i,c in enumerate(''.join(t[:w]for t in c)):\n"
"    if c=='#':\n"
"      a(i)\n"
"      f[i]=0\n"
"  while q:\n"
"    i=p()\n"
"    v=f[i]+1\n"
"    j,k,l,m,u=i+w,i-w,i+1,i-1,i%w\n"
"    if h*w>j and f[j]<0:\n"
"      a(j)\n"
"      f[j]=v\n"
"    if k>=0 and f[k]<0:\n"
"      a(k)\n"
"      f[k]=v\n"
"    if w>u+1and f[l]<0:\n"
"      a(l)\n"
"      f[l]=v\n"
"    if u and f[m]<0:\n"
"      a(m)\n"
"      f[m]=v\n"
"  print(v-1)\n"
"if __name__=='__main__':\n"
"  main()\n"
"\"";
  system(s);
  return 0;
}            