#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[25][25];
int X[25], Y[25];
bool vis[25][25];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct PP {
  int x, y;
  int res;
} s, q;
queue<PP> qua;
int cnt, ans;
void Init() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        X[++cnt] = i;
        Y[cnt] = j;
      }
    }
  }
}
bool Chk(int x, int y) {
  if (vis[x][y] || x < 1 || x > n || y < 1 || y > m || a[x][y] == '#')
    return false;
  return true;
}
int Bfs(int x, int y, int ex, int ey) {
  s.x = x, s.y = y, s.res = 0;
  qua.push(s);
  while (!qua.empty()) {
    s = qua.front();
    qua.pop();
    if (s.x == ex && s.y == ey) return s.res;
    for (int i = 0; i < 4; i++) {
      q.x = s.x + dx[i], q.y = s.y + dy[i];
      q.res = s.res + 1;
      if (Chk(q.x, q.y)) continue;
      vis[q.x][q.y] = 1;
      qua.push(q);
    }
  }
}
int main() {
  Init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        for (int k = 1; k <= cnt; k++) {
          memset(vis, 0, sizeof(vis));
          while (!qua.empty()) qua.pop();
          int tmp = Bfs(i, j, X[k], Y[k]);
          ans = max(ans, tmp);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
