from collections import deque



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

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



sl = []

flag = False

for i in range(h):

    for j in range(w):

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

            sl.append([i, j])



q = deque()

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

ans = 0

for sh, sw in sl:

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

    q.append((sh, sw, 0))

    while q:

        ph, pw, k = q.pop()

        if c[ph][pw] == 0:

            ans = max(ans, k)

            c[ph][pw] = 1

            for dh, dw in dire:

                hdh, wdw = ph+dh, pw+dw

                if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0:

                    if s[hdh][wdw] == '.':

                        q.appendleft((hdh, wdw, k+1))



print(ans)
def main():

    import sys

    readline = sys.stdin.buffer.readline



    from collections import deque



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

    s = ['#'*(w+2)] + ['#' + readline().rstrip().decode('utf-8') + '#' for _ in range(h)] + ['#'*(w+2)]



    l = []

    for i in range(h+2):

        for j in range(w+2):

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

                l.append((i, j))

    dire = ((0, 1), (0, -1), (1, 0), (-1, 0))

    q = deque()

    ans = 0

    for hh, ww in l:

        q.appendleft((hh, ww, 0))

        c = [[0]*(w+2) for _ in range(h+2)]

        while q:

            ha, wa, ca = q.pop()

            if c[ha][wa] == 0:

                c[ha][wa] = 1

                ans = max(ans, ca)

                for dh, dw in dire:

                    hdh, wdw = ha+dh, wa+dw

                    if s[hdh][wdw] == '.' and c[hdh][wdw] == 0:

                        q.appendleft((hdh, wdw, ca+1))

    print(ans)



main()
from collections import deque

h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
sl = []
flag = False
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            sl.append([i, j])
q = deque()
dire = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
for sh, sw in sl:
    c = [[0] * w for _ in range(h)]
    q.append((sh, sw, 0))
    while q:
        ph, pw, k = q.pop()
        if c[ph][pw] == 0:
            ans = max(ans, k)
            c[ph][pw] = 1
            for dh, dw in dire:
                hdh, wdw = ph + dh, pw + dw
                if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0:
                    if s[hdh][wdw] == ".":
                        q.appendleft((hdh, wdw, k + 1))
print(ans)

def main():
    import sys

    readline = sys.stdin.buffer.readline
    from collections import deque

    h, w = list(map(int, readline().split()))
    s = (
        ["#" * (w + 2)]
        + ["#" + readline().rstrip().decode("utf-8") + "#" for _ in range(h)]
        + ["#" * (w + 2)]
    )
    l = []
    for i in range(h + 2):
        for j in range(w + 2):
            if s[i][j] == ".":
                l.append((i, j))
    dire = ((0, 1), (0, -1), (1, 0), (-1, 0))
    q = deque()
    ans = 0
    for hh, ww in l:
        q.appendleft((hh, ww, 0))
        c = [[0] * (w + 2) for _ in range(h + 2)]
        while q:
            ha, wa, ca = q.pop()
            if c[ha][wa] == 0:
                c[ha][wa] = 1
                ans = max(ans, ca)
                for dh, dw in dire:
                    hdh, wdw = ha + dh, wa + dw
                    if s[hdh][wdw] == "." and c[hdh][wdw] == 0:
                        q.appendleft((hdh, wdw, ca + 1))
    print(ans)


main()

-from collections import deque +def main(): +    import sys -h, w = list(map(int, input().split())) -s = [list(eval(input())) for _ in range(h)] -sl = [] -flag = False -for i in range(h): -    for j in range(w): -        if s[i][j] == ".": -            sl.append([i, j]) -q = deque() -dire = [(0, 1), (0, -1), (1, 0), (-1, 0)] -ans = 0 -for sh, sw in sl: -    c = [[0] * w for _ in range(h)] -    q.append((sh, sw, 0)) -    while q: -        ph, pw, k = q.pop() -        if c[ph][pw] == 0: -            ans = max(ans, k) -            c[ph][pw] = 1 -            for dh, dw in dire: -                hdh, wdw = ph + dh, pw + dw -                if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0: -                    if s[hdh][wdw] == ".": -                        q.appendleft((hdh, wdw, k + 1)) -print(ans) +    readline = sys.stdin.buffer.readline +    from collections import deque + +    h, w = list(map(int, readline().split())) +    s = ( +        ["#" * (w + 2)] +        + ["#" + readline().rstrip().decode("utf-8") + "#" for _ in range(h)] +        + ["#" * (w + 2)] +    ) +    l = [] +    for i in range(h + 2): +        for j in range(w + 2): +            if s[i][j] == ".": +                l.append((i, j)) +    dire = ((0, 1), (0, -1), (1, 0), (-1, 0)) +    q = deque() +    ans = 0 +    for hh, ww in l: +        q.appendleft((hh, ww, 0)) +        c = [[0] * (w + 2) for _ in range(h + 2)] +        while q: +            ha, wa, ca = q.pop() +            if c[ha][wa] == 0: +                c[ha][wa] = 1 +                ans = max(ans, ca) +                for dh, dw in dire: +                    hdh, wdw = ha + dh, wa + dw +                    if s[hdh][wdw] == "." and c[hdh][wdw] == 0: +                        q.appendleft((hdh, wdw, ca + 1)) +    print(ans) + + +main()