#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools


def main():
  H, W = map(int, input().split())
  M = list(itertools.chain.from_iterable([[c == '.' for c in input().strip()] for _ in range(H)]))
  size = W * H
  dist = [[size] * (size) for _ in range(size)]

  for i in range(size):
    if not M[i]:
      continue

    x, y = i % W, i // W

    if x > 0 and M[i - 1]:
      dist[i][i - 1] = 1
      dist[i - 1][i] = 1

    if y > 0 and M[i - W]:
      dist[i][i - W] = 1
      dist[i - W][i] = 1

  for i in range(size):
    for j in range(size):
      for k in range(size):
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

  r = 1

  for v in itertools.chain.from_iterable(dist):
    if v < 15:
      r = max(r, v)

  print(r)


if __name__ == '__main__':
  main()
