h, w = list(map(int, input().split()))

grid = [eval(input()) for _ in range(h)]



ans = 0



for i in range(h):

    for j in range(w):

        if grid[i][j] == ".":

            q = [(i, j)]

            dist = [[-1]*w for _ in range(h)]

            dist[i][j] = 0

            while q:

                x, y = q.pop(0)

                for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):

                    nx, ny = x+dx, y+dy

                    if not (nx in range(h) and ny in range(w)):

                        continue

                    if grid[nx][ny] == "#":

                        continue

                    if dist[nx][ny] == -1:

                        dist[nx][ny] = dist[x][y] + 1

                        q.append((nx, ny))

            ans = max(ans, max([max([j for j in i]) for i in dist]))



print(ans)
h,w = list(map(int,input().split()))

ls = [eval(input()) for _ in range(h)]

from collections import deque

a = 0

for i in range(h):

  for j in range(w):

    if ls[i][j]=='#': continue

    d = [[-1]*w for _ in range(h)]

    d[i][j] = 0

    q = deque([(i,j)])

    while q:

      x,y = q.popleft()

      for dx,dy in ((1,0),(0,1),(-1,0),(0,-1)):

        nx,ny = x+dx,y+dy

        if not (0<=nx<h and 0<=ny<w): continue

        if ls[nx][ny]=='.' and d[nx][ny]==-1:

          d[nx][ny] = d[x][y]+1

          q.append((nx,ny))

    a = max(a,max(max(j for j in i) for i in d))

print(a)
h, w = list(map(int, input().split()))
grid = [eval(input()) for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == ".":
            q = [(i, j)]
            dist = [[-1] * w for _ in range(h)]
            dist[i][j] = 0
            while q:
                x, y = q.pop(0)
                for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nx, ny = x + dx, y + dy
                    if not (nx in range(h) and ny in range(w)):
                        continue
                    if grid[nx][ny] == "#":
                        continue
                    if dist[nx][ny] == -1:
                        dist[nx][ny] = dist[x][y] + 1
                        q.append((nx, ny))
            ans = max(ans, max([max([j for j in i]) for i in dist]))
print(ans)

h, w = list(map(int, input().split()))
ls = [eval(input()) for _ in range(h)]
from collections import deque

a = 0
for i in range(h):
    for j in range(w):
        if ls[i][j] == "#":
            continue
        d = [[-1] * w for _ in range(h)]
        d[i][j] = 0
        q = deque([(i, j)])
        while q:
            x, y = q.popleft()
            for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
                nx, ny = x + dx, y + dy
                if not (0 <= nx < h and 0 <= ny < w):
                    continue
                if ls[nx][ny] == "." and d[nx][ny] == -1:
                    d[nx][ny] = d[x][y] + 1
                    q.append((nx, ny))
        a = max(a, max(max(j for j in i) for i in d))
print(a)

-grid = [eval(input()) for _ in range(h)] -ans = 0 +ls = [eval(input()) for _ in range(h)] +from collections import deque + +a = 0 -        if grid[i][j] == ".": -            q = [(i, j)] -            dist = [[-1] * w for _ in range(h)] -            dist[i][j] = 0 -            while q: -                x, y = q.pop(0) -                for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): -                    nx, ny = x + dx, y + dy -                    if not (nx in range(h) and ny in range(w)): -                        continue -                    if grid[nx][ny] == "#": -                        continue -                    if dist[nx][ny] == -1: -                        dist[nx][ny] = dist[x][y] + 1 -                        q.append((nx, ny)) -            ans = max(ans, max([max([j for j in i]) for i in dist])) -print(ans) +        if ls[i][j] == "#": +            continue +        d = [[-1] * w for _ in range(h)] +        d[i][j] = 0 +        q = deque([(i, j)]) +        while q: +            x, y = q.popleft() +            for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): +                nx, ny = x + dx, y + dy +                if not (0 <= nx < h and 0 <= ny < w): +                    continue +                if ls[nx][ny] == "." and d[nx][ny] == -1: +                    d[nx][ny] = d[x][y] + 1 +                    q.append((nx, ny)) +        a = max(a, max(max(j for j in i) for i in d)) +print(a)