from collections import deque

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

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

a=[[400]*w for _ in range(h)]

ans=0

def bfs(b,i,j):

    b[i][j]=0

    seen=[[0]*w for _ in range(h)]

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

    while len(todo)>0:

        x,y=todo.popleft()

        if seen[x][y]==1:

            continue

        seen[x][y]=1

        if x>0 and seen[x-1][y]==0 and s[x-1][y]=='.':

            b[x-1][y]=b[x][y]+1

            todo.append((x-1,y))

        if x>0 and s[x-1][y]=='#':

            seen[x-1][y]=1

        if x<h-1 and seen[x+1][y]==0 and s[x+1][y]=='.':

            b[x+1][y]=b[x][y]+1

            todo.append((x+1,y))

        if x<h-1 and s[x+1][y]=='#':

            seen[x+1][y]=1

        if y>0 and seen[x][y-1]==0 and s[x][y-1]=='.':

            b[x][y-1]=b[x][y]+1

            todo.append((x,y-1))

        if y>0 and s[x][y-1]=='#':

            seen[x][y-1]=1

        if y<w-1 and seen[x][y+1]==0 and s[x][y+1]=='.':

            b[x][y+1]=b[x][y]+1

            todo.append((x,y+1))

        if y<w-1 and s[x][y+1]=='#':

            seen[x][y+1]=1

    ret=0 

    for bi in b:

        for bij in bi:

            if bij<400:

                ret=max(ret,bij)

    #print(b)

    return ret



for i in range(h):

    for j in range(w):

        if s[i][j]=='.':

            b=a

            ans=max(ans,bfs(b,i,j))

print(ans)

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

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

from collections import deque

def bfs(i,j):

    if s[i][j]=='#':

        return 0

    ret=-1

    todo=[]

    next_todo=[(i,j)]

    seen=[[0]*w for _ in range(h)]

    seen[i][j]=1

    while next_todo:

        ret+=1

        todo=deque(next_todo)

        next_todo=[]

        while todo:

            hi,wi=todo.popleft()

            if hi>0 and seen[hi-1][wi]==0 and s[hi-1][wi]=='.':

                seen[hi-1][wi]=1

                next_todo.append((hi-1,wi))

            if hi<h-1 and seen[hi+1][wi]==0 and s[hi+1][wi]=='.':

                seen[hi+1][wi]=1

                next_todo.append((hi+1,wi))

            if wi>0 and seen[hi][wi-1]==0 and s[hi][wi-1]=='.':

                seen[hi][wi-1]=1

                next_todo.append((hi,wi-1))

            if wi<w-1 and seen[hi][wi+1]==0 and s[hi][wi+1]=='.':

                seen[hi][wi+1]=1

                next_todo.append((hi,wi+1))

    return ret

ans=0

for i in range(h):

    for j in range(w):

        ans=max(ans,bfs(i,j))

print(ans)

from collections import deque

h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
a = [[400] * w for _ in range(h)]
ans = 0


def bfs(b, i, j):
    b[i][j] = 0
    seen = [[0] * w for _ in range(h)]
    todo = deque([(i, j)])
    while len(todo) > 0:
        x, y = todo.popleft()
        if seen[x][y] == 1:
            continue
        seen[x][y] = 1
        if x > 0 and seen[x - 1][y] == 0 and s[x - 1][y] == ".":
            b[x - 1][y] = b[x][y] + 1
            todo.append((x - 1, y))
        if x > 0 and s[x - 1][y] == "#":
            seen[x - 1][y] = 1
        if x < h - 1 and seen[x + 1][y] == 0 and s[x + 1][y] == ".":
            b[x + 1][y] = b[x][y] + 1
            todo.append((x + 1, y))
        if x < h - 1 and s[x + 1][y] == "#":
            seen[x + 1][y] = 1
        if y > 0 and seen[x][y - 1] == 0 and s[x][y - 1] == ".":
            b[x][y - 1] = b[x][y] + 1
            todo.append((x, y - 1))
        if y > 0 and s[x][y - 1] == "#":
            seen[x][y - 1] = 1
        if y < w - 1 and seen[x][y + 1] == 0 and s[x][y + 1] == ".":
            b[x][y + 1] = b[x][y] + 1
            todo.append((x, y + 1))
        if y < w - 1 and s[x][y + 1] == "#":
            seen[x][y + 1] = 1
    ret = 0
    for bi in b:
        for bij in bi:
            if bij < 400:
                ret = max(ret, bij)
    # print(b)
    return ret


for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            b = a
            ans = max(ans, bfs(b, i, j))
print(ans)

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


def bfs(i, j):
    if s[i][j] == "#":
        return 0
    ret = -1
    todo = []
    next_todo = [(i, j)]
    seen = [[0] * w for _ in range(h)]
    seen[i][j] = 1
    while next_todo:
        ret += 1
        todo = deque(next_todo)
        next_todo = []
        while todo:
            hi, wi = todo.popleft()
            if hi > 0 and seen[hi - 1][wi] == 0 and s[hi - 1][wi] == ".":
                seen[hi - 1][wi] = 1
                next_todo.append((hi - 1, wi))
            if hi < h - 1 and seen[hi + 1][wi] == 0 and s[hi + 1][wi] == ".":
                seen[hi + 1][wi] = 1
                next_todo.append((hi + 1, wi))
            if wi > 0 and seen[hi][wi - 1] == 0 and s[hi][wi - 1] == ".":
                seen[hi][wi - 1] = 1
                next_todo.append((hi, wi - 1))
            if wi < w - 1 and seen[hi][wi + 1] == 0 and s[hi][wi + 1] == ".":
                seen[hi][wi + 1] = 1
                next_todo.append((hi, wi + 1))
    return ret


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(ans)

+h, w = list(map(int, input().split())) +s = [eval(input()) for _ in range(h)] -h, w = list(map(int, input().split())) -s = [eval(input()) for _ in range(h)] -a = [[400] * w for _ in range(h)] -ans = 0 - -def bfs(b, i, j): -    b[i][j] = 0 +def bfs(i, j): +    if s[i][j] == "#": +        return 0 +    ret = -1 +    todo = [] +    next_todo = [(i, j)] -    todo = deque([(i, j)]) -    while len(todo) > 0: -        x, y = todo.popleft() -        if seen[x][y] == 1: -            continue -        seen[x][y] = 1 -        if x > 0 and seen[x - 1][y] == 0 and s[x - 1][y] == ".": -            b[x - 1][y] = b[x][y] + 1 -            todo.append((x - 1, y)) -        if x > 0 and s[x - 1][y] == "#": -            seen[x - 1][y] = 1 -        if x < h - 1 and seen[x + 1][y] == 0 and s[x + 1][y] == ".": -            b[x + 1][y] = b[x][y] + 1 -            todo.append((x + 1, y)) -        if x < h - 1 and s[x + 1][y] == "#": -            seen[x + 1][y] = 1 -        if y > 0 and seen[x][y - 1] == 0 and s[x][y - 1] == ".": -            b[x][y - 1] = b[x][y] + 1 -            todo.append((x, y - 1)) -        if y > 0 and s[x][y - 1] == "#": -            seen[x][y - 1] = 1 -        if y < w - 1 and seen[x][y + 1] == 0 and s[x][y + 1] == ".": -            b[x][y + 1] = b[x][y] + 1 -            todo.append((x, y + 1)) -        if y < w - 1 and s[x][y + 1] == "#": -            seen[x][y + 1] = 1 -    ret = 0 -    for bi in b: -        for bij in bi: -            if bij < 400: -                ret = max(ret, bij) -    # print(b) +    seen[i][j] = 1 +    while next_todo: +        ret += 1 +        todo = deque(next_todo) +        next_todo = [] +        while todo: +            hi, wi = todo.popleft() +            if hi > 0 and seen[hi - 1][wi] == 0 and s[hi - 1][wi] == ".": +                seen[hi - 1][wi] = 1 +                next_todo.append((hi - 1, wi)) +            if hi < h - 1 and seen[hi + 1][wi] == 0 and s[hi + 1][wi] == ".": +                seen[hi + 1][wi] = 1 +                next_todo.append((hi + 1, wi)) +            if wi > 0 and seen[hi][wi - 1] == 0 and s[hi][wi - 1] == ".": +                seen[hi][wi - 1] = 1 +                next_todo.append((hi, wi - 1)) +            if wi < w - 1 and seen[hi][wi + 1] == 0 and s[hi][wi + 1] == ".": +                seen[hi][wi + 1] = 1 +                next_todo.append((hi, wi + 1)) +ans = 0 -        if s[i][j] == ".": -            b = a -            ans = max(ans, bfs(b, i, j)) +        ans = max(ans, bfs(i, j))