import copy
import queue

H,W = map(int, input().split())
def check(x,y):
    global W,H
    if x<0 or y<0 or x>=W or y>=H:
        return False
    return True

m = []
visit = []
for _ in range(H):
    S = list(input())
    m.append(S)
    l = [-1]*W
    visit.append(l)

visit_copy = copy.deepcopy(visit)
max = 0

for i in range(H):
    for j in range(W):
        sy = i
        sx = j
        q = queue.Queue()
        visit[sy][sx] = 0
        q.put([sy,sx])
        while not (q.empty()):
            y,x = q.get()
            if m[y][x]=="#":
                continue

            if check(x+1,y)==True:
                if visit[y][x+1]==-1 and m[y][x+1]==".":  
                    visit[y][x+1] = visit[y][x] + 1
                    if visit[y][x+1] > max:
                        max = visit[y][x+1]

                    q.put([y,x+1])
            if check(x,y+1)==True:
                if visit[y+1][x]==-1 and m[y+1][x]==".":  
                    visit[y+1][x] = visit[y][x] + 1
                    if visit[y+1][x] > max:
                        max = visit[y+1][x]

                    q.put([y+1,x])
            if check(x,y-1)==True:
                if visit[y-1][x]==-1 and m[y-1][x]==".":  
                    visit[y-1][x] = visit[y][x] + 1
                    if visit[y-1][x] > max:
                        max = visit[y-1][x]

                    q.put([y-1,x])
            if check(x-1,y)==True:
                if visit[y][x-1]==-1 and m[y][x-1]==".":  
                    visit[y][x-1] = visit[y][x] + 1
                    if visit[y][x-1] > max:
                        max = visit[y][x-1]

                    q.put([y,x-1])
    visit = copy.deepcopy(visit_copy)

print(max)