from collections import deque
import math
maxloc = -10
h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
for y in range(h):
    for x in range(w):
        if maze[y][x]=='.':
            maze[y][x]=1000000

for i in range(h):
  for j in range(w):
    sy = i
    sx = j
    if(maze[sy-1][sx-1] != '#'):
      maze[sy-1][sx-1]=0
      for k in range(h):
        for l in range(w):
          gy = k
          gx = l
          if(maze[gy-1][gx-1] != '#'):
            que = deque([[sy-1, sx-1]])
            while que:
              y, x = que.popleft()
              for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
                nexty, nextx = y+i, x+j
                dist = maze[nexty][nextx]
                if(dist != '#'):
                  if dist > maze[y][x]+1:
                    maze[nexty][nextx] = maze[y][x]+1
                    que.append([nexty, nextx])
            if(int(maze[gy-1][gx-1])>maxloc):
              maxloc = maze[gy-1][gx-1]
            
print(maxloc)