#include <bits/stdc++.h>
using namespace std;
char s[21][21];
int h, w, d[501][501];
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 1; i <= h; ++i) scanf("%s", s[i] + 1);
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j)
      if (s[i][j] == '.') {
        int id = (i - 1) * w + j - 1;
        if (s[i - 1][j] == '.') d[id][id - w] = 1;
        if (s[i + 1][j] == '.') d[id][id + w] = 1;
        if (s[i][j - 1] == '.') d[id][id - 1] = 1;
        if (s[i][j + 1] == '.') d[id][id + 1] = 1;
      }
  for (int k = 0; k < h * w; ++k)
    for (int i = 0; i < h * w; ++i)
      for (int j = 0; j < h * w; ++j)
        if (d[i][k] && d[k][j]) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
          if (d[i][j] == 0) d[i][j] = d[i][k] + d[k][j];
        }
  int ans = 0;
  for (int i = 0; i < h * w; ++i)
    for (int j = 0; j <= h * w; ++j) ans = max(ans, d[i][j]);
  printf("%d\n", ans);
}
