from collections import deque

from copy import deepcopy



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

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

r = 0

for i in range(h):

  for j in range(w):

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

      b = deepcopy(a)

      q = deque()

      b[i][j] = 0

      q.append((i, j))

      while(q):

        i, j = q.popleft()

        r = max(r, b[i][j])

        for di in range(-1, 2):

          i1 = i + di

          if 0 <= i1 < h:

            for dj in range(di % 2 - 1, 2, 2):                

              j1 = j + dj

              if 0 <= j1 < w and b[i1][j1] == '.':

                b[i1][j1] = b[i][j] + 1

                q.append((i1, j1))

print(r)

from collections import deque



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

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

r = 0

for i in range(h):

  for j in range(w):

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

      b = list(map(list, a))

      q = deque()

      b[i][j] = 0

      q.append((i, j))

      while(q):

        i, j = q.popleft()

        r = max(r, b[i][j])

        for di in range(-1, 2):

          i1 = i + di

          if 0 <= i1 < h:

            for dj in range(di % 2 - 1, 2, 2):                

              j1 = j + dj

              if 0 <= j1 < w and b[i1][j1] == '.':

                b[i1][j1] = b[i][j] + 1

                q.append((i1, j1))

print(r)

from collections import deque
from copy import deepcopy

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
r = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            b = deepcopy(a)
            q = deque()
            b[i][j] = 0
            q.append((i, j))
            while q:
                i, j = q.popleft()
                r = max(r, b[i][j])
                for di in range(-1, 2):
                    i1 = i + di
                    if 0 <= i1 < h:
                        for dj in range(di % 2 - 1, 2, 2):
                            j1 = j + dj
                            if 0 <= j1 < w and b[i1][j1] == ".":
                                b[i1][j1] = b[i][j] + 1
                                q.append((i1, j1))
print(r)

from collections import deque

h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
r = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            b = list(map(list, a))
            q = deque()
            b[i][j] = 0
            q.append((i, j))
            while q:
                i, j = q.popleft()
                r = max(r, b[i][j])
                for di in range(-1, 2):
                    i1 = i + di
                    if 0 <= i1 < h:
                        for dj in range(di % 2 - 1, 2, 2):
                            j1 = j + dj
                            if 0 <= j1 < w and b[i1][j1] == ".":
                                b[i1][j1] = b[i][j] + 1
                                q.append((i1, j1))
print(r)

-from copy import deepcopy -a = [list(eval(input())) for _ in range(h)] +a = [eval(input()) for _ in range(h)] -            b = deepcopy(a) +            b = list(map(list, a))