def main():

    import numpy as np

    def bfs(S,s,h,w):

        dist = np.ones((h,w))*-1

        dist[s[0],s[1]]=0

        que = [s]

        while len(que)>0:

            v = que.pop(0)

            if v[0]+1<h:

                if S[v[0]+1][v[1]]=='.' and dist[v[0]+1][v[1]] == -1:

                    dist[v[0]+1][v[1]]=dist[v[0]][v[1]]+1

                    que.append([v[0]+1,v[1]])

            if v[0]-1>-1:

                if S[v[0]-1][v[1]]=='.' and dist[v[0]-1][v[1]]==-1:

                    dist[v[0]-1][v[1]]=dist[v[0]][v[1]]+1

                    que.append([v[0]-1,v[1]])

            if v[1]+1<w:

                if S[v[0]][v[1]+1]=='.' and dist[v[0]][v[1]+1]==-1:

                    dist[v[0]][v[1]+1]=dist[v[0]][v[1]]+1

                    que.append([v[0],v[1]+1])

            if v[1]-1>-1:

                if S[v[0]][v[1]-1]=='.' and dist[v[0]][v[1]-1]==-1:

                    dist[v[0]][v[1]-1]=dist[v[0]][v[1]]+1

                    que.append([v[0],v[1]-1])

        return np.max(dist)



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

    S = []

    for i in range(h):

        S.append(eval(input()))

    m = 0

    spot = []

    for i in range(h):

        for j in range(w):

            spot.append([i,j])

    for i in range(len(spot)):

        s = spot[i]

        if S[s[0]][s[1]]=='#':

            continue

        d = bfs(S,s,h,w)

        if m<d:

            m = d

    print((int(m)))





if __name__ == "__main__":

    main()
def main():

    import numpy as np

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

    maize = []

    for i in range(h):

        s = eval(input())

        maize.append(s)

    ans = 0

    for i in range(h):

        for j in range(w):

            que = [[i,j]]

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

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

                dis[i][j] = 0

                while len(que)>0:

                    q = que.pop(0)

                    if q[0]>0:

                        n = [q[0]-1,q[1]]

                        if maize[n[0]][n[1]]=='.':

                            if dis[n[0]][n[1]]==-1:

                                dis[n[0]][n[1]] = dis[q[0]][q[1]]+1

                                que.append(n)

                    if q[0] < h-1:

                        n = [q[0]+1,q[1]]

                        if maize[n[0]][n[1]]=='.':

                            if dis[n[0]][n[1]]==-1:

                                dis[n[0]][n[1]] = dis[q[0]][q[1]]+1

                                que.append(n)

                    if q[1] > 0:

                        n = [q[0],q[1]-1]

                        if maize[n[0]][n[1]]=='.':

                            if dis[n[0]][n[1]]==-1:

                                dis[n[0]][n[1]] = dis[q[0]][q[1]]+1

                                que.append(n)

                    if q[1] < w-1:

                        n = [q[0],q[1]+1]

                        if maize[n[0]][n[1]]=='.':

                            if dis[n[0]][n[1]]==-1:

                                dis[n[0]][n[1]] = dis[q[0]][q[1]]+1

                                que.append(n)

                dis = np.array(dis)

                if np.max(dis)>ans:

                    ans = np.max(dis)

    print(ans)

    



if __name__ == "__main__":

    main()

def main():
    import numpy as np

    def bfs(S, s, h, w):
        dist = np.ones((h, w)) * -1
        dist[s[0], s[1]] = 0
        que = [s]
        while len(que) > 0:
            v = que.pop(0)
            if v[0] + 1 < h:
                if S[v[0] + 1][v[1]] == "." and dist[v[0] + 1][v[1]] == -1:
                    dist[v[0] + 1][v[1]] = dist[v[0]][v[1]] + 1
                    que.append([v[0] + 1, v[1]])
            if v[0] - 1 > -1:
                if S[v[0] - 1][v[1]] == "." and dist[v[0] - 1][v[1]] == -1:
                    dist[v[0] - 1][v[1]] = dist[v[0]][v[1]] + 1
                    que.append([v[0] - 1, v[1]])
            if v[1] + 1 < w:
                if S[v[0]][v[1] + 1] == "." and dist[v[0]][v[1] + 1] == -1:
                    dist[v[0]][v[1] + 1] = dist[v[0]][v[1]] + 1
                    que.append([v[0], v[1] + 1])
            if v[1] - 1 > -1:
                if S[v[0]][v[1] - 1] == "." and dist[v[0]][v[1] - 1] == -1:
                    dist[v[0]][v[1] - 1] = dist[v[0]][v[1]] + 1
                    que.append([v[0], v[1] - 1])
        return np.max(dist)

    h, w = list(map(int, input().split()))
    S = []
    for i in range(h):
        S.append(eval(input()))
    m = 0
    spot = []
    for i in range(h):
        for j in range(w):
            spot.append([i, j])
    for i in range(len(spot)):
        s = spot[i]
        if S[s[0]][s[1]] == "#":
            continue
        d = bfs(S, s, h, w)
        if m < d:
            m = d
    print((int(m)))


if __name__ == "__main__":
    main()

def main():
    import numpy as np

    h, w = list(map(int, input().split()))
    maize = []
    for i in range(h):
        s = eval(input())
        maize.append(s)
    ans = 0
    for i in range(h):
        for j in range(w):
            que = [[i, j]]
            if maize[i][j] == ".":
                dis = [[-1 for i in range(w)] for i in range(h)]
                dis[i][j] = 0
                while len(que) > 0:
                    q = que.pop(0)
                    if q[0] > 0:
                        n = [q[0] - 1, q[1]]
                        if maize[n[0]][n[1]] == ".":
                            if dis[n[0]][n[1]] == -1:
                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1
                                que.append(n)
                    if q[0] < h - 1:
                        n = [q[0] + 1, q[1]]
                        if maize[n[0]][n[1]] == ".":
                            if dis[n[0]][n[1]] == -1:
                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1
                                que.append(n)
                    if q[1] > 0:
                        n = [q[0], q[1] - 1]
                        if maize[n[0]][n[1]] == ".":
                            if dis[n[0]][n[1]] == -1:
                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1
                                que.append(n)
                    if q[1] < w - 1:
                        n = [q[0], q[1] + 1]
                        if maize[n[0]][n[1]] == ".":
                            if dis[n[0]][n[1]] == -1:
                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1
                                que.append(n)
                dis = np.array(dis)
                if np.max(dis) > ans:
                    ans = np.max(dis)
    print(ans)


if __name__ == "__main__":
    main()

-    def bfs(S, s, h, w): -        dist = np.ones((h, w)) * -1 -        dist[s[0], s[1]] = 0 -        que = [s] -        while len(que) > 0: -            v = que.pop(0) -            if v[0] + 1 < h: -                if S[v[0] + 1][v[1]] == "." and dist[v[0] + 1][v[1]] == -1: -                    dist[v[0] + 1][v[1]] = dist[v[0]][v[1]] + 1 -                    que.append([v[0] + 1, v[1]]) -            if v[0] - 1 > -1: -                if S[v[0] - 1][v[1]] == "." and dist[v[0] - 1][v[1]] == -1: -                    dist[v[0] - 1][v[1]] = dist[v[0]][v[1]] + 1 -                    que.append([v[0] - 1, v[1]]) -            if v[1] + 1 < w: -                if S[v[0]][v[1] + 1] == "." and dist[v[0]][v[1] + 1] == -1: -                    dist[v[0]][v[1] + 1] = dist[v[0]][v[1]] + 1 -                    que.append([v[0], v[1] + 1]) -            if v[1] - 1 > -1: -                if S[v[0]][v[1] - 1] == "." and dist[v[0]][v[1] - 1] == -1: -                    dist[v[0]][v[1] - 1] = dist[v[0]][v[1]] + 1 -                    que.append([v[0], v[1] - 1]) -        return np.max(dist) - -    S = [] +    maize = [] -        S.append(eval(input())) -    m = 0 -    spot = [] +        s = eval(input()) +        maize.append(s) +    ans = 0 -            spot.append([i, j]) -    for i in range(len(spot)): -        s = spot[i] -        if S[s[0]][s[1]] == "#": -            continue -        d = bfs(S, s, h, w) -        if m < d: -            m = d -    print((int(m))) +            que = [[i, j]] +            if maize[i][j] == ".": +                dis = [[-1 for i in range(w)] for i in range(h)] +                dis[i][j] = 0 +                while len(que) > 0: +                    q = que.pop(0) +                    if q[0] > 0: +                        n = [q[0] - 1, q[1]] +                        if maize[n[0]][n[1]] == ".": +                            if dis[n[0]][n[1]] == -1: +                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1 +                                que.append(n) +                    if q[0] < h - 1: +                        n = [q[0] + 1, q[1]] +                        if maize[n[0]][n[1]] == ".": +                            if dis[n[0]][n[1]] == -1: +                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1 +                                que.append(n) +                    if q[1] > 0: +                        n = [q[0], q[1] - 1] +                        if maize[n[0]][n[1]] == ".": +                            if dis[n[0]][n[1]] == -1: +                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1 +                                que.append(n) +                    if q[1] < w - 1: +                        n = [q[0], q[1] + 1] +                        if maize[n[0]][n[1]] == ".": +                            if dis[n[0]][n[1]] == -1: +                                dis[n[0]][n[1]] = dis[q[0]][q[1]] + 1 +                                que.append(n) +                dis = np.array(dis) +                if np.max(dis) > ans: +                    ans = np.max(dis) +    print(ans)