#python3

from collections import deque



INF = int(1e20)

di = [1, 0, -1, 0]

dj = [0, 1, 0, -1]



def main():

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

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

    ans = 0



    for si in range(h):

        for sj in range(w):

            if maze[si][sj] == '#':

                continue

            dist = [[INF for i in range(w)] for j in range(h)]

            q = deque()



            def update(i, j, x):

                if dist[i][j] != INF:

                    return None

                dist[i][j] = x

                q.append((i,j))

            

            update(si, sj, 0)

            while len(q) != 0:

                i, j = q.popleft()



                for dir in range(4):

                    ni = i+di[dir]

                    nj = j+dj[dir]

                    if (ni<0)|(ni>=h)|(nj<0)|(nj>=w):

                        continue

                    if maze[ni][nj] == '#':

                        continue

                    update(ni, nj, dist[i][j]+1)

        

            for i in range(h):

                for j in range(w):

                    if dist[i][j] == INF:

                        continue

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

    print(ans)



main()
#python3

from collections import deque

INF = int(1e9)

d = [(1, 0), (-1, 0), (0, 1), (0, -1)]



def main():

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

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



    ans = -1

    for si in range(h):

        for sj in range(w):

            if maze[si][sj] == '#':

                continue

            

            dist = [[INF for _ in range(w)] for _ in range(h)]

            Q = deque()

            Q.append((si, sj))

            dist[si][sj] = 0

            while len(Q) > 0:

                pi, pj = Q.popleft()



                for di, dj in d:

                    x = pi + di

                    y = pj + dj

                    if (x < 0) | (y < 0) | (x >= h) | (y >= w):

                        continue

                    if maze[x][y] == '#':

                        continue 

                    if dist[x][y] != INF:

                        continue



                    Q.append((x, y))

                    dist[x][y] = dist[pi][pj] + 1                



            for i in range(h):

                for j in range(w):

                    if dist[i][j] == INF:

                        continue            



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

    

    print(ans)

main()
# python3
from collections import deque

INF = int(1e20)
di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]


def main():
    h, w = list(map(int, input().split()))
    maze = [eval(input()) for i in range(h)]
    ans = 0
    for si in range(h):
        for sj in range(w):
            if maze[si][sj] == "#":
                continue
            dist = [[INF for i in range(w)] for j in range(h)]
            q = deque()

            def update(i, j, x):
                if dist[i][j] != INF:
                    return None
                dist[i][j] = x
                q.append((i, j))

            update(si, sj, 0)
            while len(q) != 0:
                i, j = q.popleft()
                for dir in range(4):
                    ni = i + di[dir]
                    nj = j + dj[dir]
                    if (ni < 0) | (ni >= h) | (nj < 0) | (nj >= w):
                        continue
                    if maze[ni][nj] == "#":
                        continue
                    update(ni, nj, dist[i][j] + 1)
            for i in range(h):
                for j in range(w):
                    if dist[i][j] == INF:
                        continue
                    ans = max(ans, dist[i][j])
    print(ans)


main()

# python3
from collections import deque

INF = int(1e9)
d = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def main():
    h, w = list(map(int, input().split()))
    maze = [eval(input()) for _ in range(h)]
    ans = -1
    for si in range(h):
        for sj in range(w):
            if maze[si][sj] == "#":
                continue
            dist = [[INF for _ in range(w)] for _ in range(h)]
            Q = deque()
            Q.append((si, sj))
            dist[si][sj] = 0
            while len(Q) > 0:
                pi, pj = Q.popleft()
                for di, dj in d:
                    x = pi + di
                    y = pj + dj
                    if (x < 0) | (y < 0) | (x >= h) | (y >= w):
                        continue
                    if maze[x][y] == "#":
                        continue
                    if dist[x][y] != INF:
                        continue
                    Q.append((x, y))
                    dist[x][y] = dist[pi][pj] + 1
            for i in range(h):
                for j in range(w):
                    if dist[i][j] == INF:
                        continue
                    ans = max(ans, dist[i][j])
    print(ans)


main()

-INF = int(1e20) -di = [1, 0, -1, 0] -dj = [0, 1, 0, -1] +INF = int(1e9) +d = [(1, 0), (-1, 0), (0, 1), (0, -1)] -    maze = [eval(input()) for i in range(h)] -    ans = 0 +    maze = [eval(input()) for _ in range(h)] +    ans = -1 -            dist = [[INF for i in range(w)] for j in range(h)] -            q = deque() - -            def update(i, j, x): -                if dist[i][j] != INF: -                    return None -                dist[i][j] = x -                q.append((i, j)) - -            update(si, sj, 0) -            while len(q) != 0: -                i, j = q.popleft() -                for dir in range(4): -                    ni = i + di[dir] -                    nj = j + dj[dir] -                    if (ni < 0) | (ni >= h) | (nj < 0) | (nj >= w): +            dist = [[INF for _ in range(w)] for _ in range(h)] +            Q = deque() +            Q.append((si, sj)) +            dist[si][sj] = 0 +            while len(Q) > 0: +                pi, pj = Q.popleft() +                for di, dj in d: +                    x = pi + di +                    y = pj + dj +                    if (x < 0) | (y < 0) | (x >= h) | (y >= w): -                    if maze[ni][nj] == "#": +                    if maze[x][y] == "#": -                    update(ni, nj, dist[i][j] + 1) +                    if dist[x][y] != INF: +                        continue +                    Q.append((x, y)) +                    dist[x][y] = dist[pi][pj] + 1