import math 
import bisect
import heapq
from collections import deque

h,w = map(int,input().split())
s = [map(int,input().split()) for _ in range(h)]
v = [ [0] * w ] * h

def bfs(i,j,s,v):
    count = 0
    mx = 0
    if s[i][j] == '#': return 0
    else:
        v[i][j] = 1
        if i+1 < h and j+1 < w :
            if v[i+1][j+1] != 1 and s[i+1][j+1] == '.':
                count += 1
                mx = max(count,mx)
                bfs(i+1,j+1,s,v)

        elif i+1 < h and j-1 > 0 :
            if v[i+1][j-1] != 1 and s[i+1][j-1] == '.':
                count += 1
                mx = max(count,mx)
                bfs(i+1,j-1,s,v)

        elif i-1 < h and j+1 > 0 :
            if v[i-1][j+1] != 1 and s[i-1][j+1] == '.':
                count += 1
                mx = max(count,mx)
                bfs(i-1,j+1,s,v)

        elif i-1 < h and j-1 > 0 :
            if v[i+1][j-1] != 1 and s[i-1][j-1] == '.':
                count += 1
                mx = max(count,mx)
                bfs(i-1,j-1,s,v)


    return mx

ans = 1000000
for i in range(h):
    for j in range(w):
        x,y = i,j
        ans = min(ans,bfs(i,j,s,v))
        