from collections import deque

def bfs(sy,sx):

  q=deque([[sy,sx]])

  visited[sy][sx]=0

  while q:

    y,x=q.popleft()

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

      ny,nx=y+dy,x+dx

      if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":continue

      if path[ny][nx]=="." and visited[ny][nx]==-1:

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

        q.append([ny,nx])

  res=-1

  for i in range(h):

    for j in range(w):

      res=max(visited[i][j],res)

  return res



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

path=[eval(input()) for i in range(h)]

visited=[[-1]*w for i in range(h)]

sy,sx=0,0

gy,gx=0,0

ans=0

for i in range(h):

  for j in range(w):

    if path[i][j]=="#":continue

    sy=i

    sx=j

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

    t=bfs(sy,sx)

    ans=max(t,ans)

print(ans)



from collections import deque

def bfs(y,x):

  q=deque([(y,x)])

  visited[y][x]=0

  while q:

    cy,cx=q.popleft()

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

      ny,nx=cy+dy,cx+dx

      if 0<=ny<h and 0<=nx<w and visited[ny][nx]==-1:

        if s[ny][nx]=="#":continue

        visited[ny][nx]=visited[cy][cx]+1

        q.append((ny,nx))

  res=0

  for i in range(h):

    for j in range(w):

      if s[i][j]!="#":

        res=max(res,visited[i][j])

  return res



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

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

ans=0

for i in range(h):

  for j in range(w):

    if s[i][j]=="#":continue

    sh=i

    sw=j

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

    ans=max(ans,bfs(sh,sw))

print(ans)



from collections import deque


def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + dy, x + dx
            if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#":
                continue
            if path[ny][nx] == "." and visited[ny][nx] == -1:
                visited[ny][nx] = visited[y][x] + 1
                q.append([ny, nx])
    res = -1
    for i in range(h):
        for j in range(w):
            res = max(visited[i][j], res)
    return res


h, w = list(map(int, input().split()))
path = [eval(input()) for i in range(h)]
visited = [[-1] * w for i in range(h)]
sy, sx = 0, 0
gy, gx = 0, 0
ans = 0
for i in range(h):
    for j in range(w):
        if path[i][j] == "#":
            continue
        sy = i
        sx = j
        visited = [[-1] * w for _ in range(h)]
        t = bfs(sy, sx)
        ans = max(t, ans)
print(ans)

from collections import deque


def bfs(y, x):
    q = deque([(y, x)])
    visited[y][x] = 0
    while q:
        cy, cx = q.popleft()
        for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            ny, nx = cy + dy, cx + dx
            if 0 <= ny < h and 0 <= nx < w and visited[ny][nx] == -1:
                if s[ny][nx] == "#":
                    continue
                visited[ny][nx] = visited[cy][cx] + 1
                q.append((ny, nx))
    res = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] != "#":
                res = max(res, visited[i][j])
    return res


h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        sh = i
        sw = j
        visited = [[-1] * w for _ in range(h)]
        ans = max(ans, bfs(sh, sw))
print(ans)

-def bfs(sy, sx): -    q = deque([[sy, sx]]) -    visited[sy][sx] = 0 +def bfs(y, x): +    q = deque([(y, x)]) +    visited[y][x] = 0 -        y, x = q.popleft() -        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]): -            ny, nx = y + dy, x + dx -            if ny < 0 or ny > h - 1 or nx < 0 or nx > w - 1 or path[ny][nx] == "#": -                continue -            if path[ny][nx] == "." and visited[ny][nx] == -1: -                visited[ny][nx] = visited[y][x] + 1 -                q.append([ny, nx]) -    res = -1 +        cy, cx = q.popleft() +        for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]: +            ny, nx = cy + dy, cx + dx +            if 0 <= ny < h and 0 <= nx < w and visited[ny][nx] == -1: +                if s[ny][nx] == "#": +                    continue +                visited[ny][nx] = visited[cy][cx] + 1 +                q.append((ny, nx)) +    res = 0 -            res = max(visited[i][j], res) +            if s[i][j] != "#": +                res = max(res, visited[i][j]) -path = [eval(input()) for i in range(h)] -visited = [[-1] * w for i in range(h)] -sy, sx = 0, 0 -gy, gx = 0, 0 +s = [eval(input()) for _ in range(h)] -        if path[i][j] == "#": +        if s[i][j] == "#": -        sy = i -        sx = j +        sh = i +        sw = j -        t = bfs(sy, sx) -        ans = max(t, ans) +        ans = max(ans, bfs(sh, sw))