#python3

from collections import deque

from collections import namedtuple



Vertex = namedtuple('Vertex', ['i', 'j'])  

INF = int(1e10)

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(Vertex(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(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
from collections import namedtuple

Vertex = namedtuple("Vertex", ["i", "j"])
INF = int(1e10)
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(Vertex(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(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()

-from collections import namedtuple -Vertex = namedtuple("Vertex", ["i", "j"]) -INF = int(1e10) +INF = int(1e20) -                q.append(Vertex(i, j)) +                q.append((i, j))