#include <bits/stdc++.h>
using namespace std;
inline void read(long long &f) {
  f = 0;
  long long x = 1;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    if (ch == '-') {
      x = -1;
    }
    ch = getchar();
  }
  while (ch <= 57 && ch >= 48) {
    f = f * 10 + ch - '0';
    ch = getchar();
  }
  f *= x;
}
long long n, m;
char c[25][25];
long long d[25][25];
long long ans = 0;
bool vst[25][25];
void BFS(long long x, long long y) {
  queue<pair<long long, long long> > q;
  q.push(make_pair(x, y));
  long long temp = 0;
  while (!q.empty()) {
    long long dx = q.front().first, dy = q.front().second;
    q.pop();
    long long p = d[dx][dy];
    if (vst[dx + 1][dy] == 0 && dx + 1 <= n && c[dx + 1][dy] != '#') {
      d[dx + 1][dy] = p + 1;
      vst[dx + 1][dy] = 1;
      temp = max(temp, d[dx + 1][dy]);
      q.push(make_pair(dx + 1, dy));
    }
    if (vst[dx][dy + 1] == 0 && dy + 1 <= m && c[dx][dy + 1] != '#') {
      d[dx][dy + 1] = p + 1;
      vst[dx][dy + 1] = 1;
      temp = max(temp, d[dx][dy + 1]);
      q.push(make_pair(dx, dy + 1));
    }
    if (vst[dx - 1][dy] == 0 && dx - 1 >= 1 && c[dx - 1][dy] != '#') {
      d[dx - 1][dy] = p + 1;
      vst[dx - 1][dy] = 1;
      temp = max(temp, d[dx - 1][dy]);
      q.push(make_pair(dx - 1, dy));
    }
    if (vst[dx][dy - 1] == 0 && dy - 1 >= 1 && c[dx][dy - 1] != '#') {
      d[dx][dy - 1] = p + 1;
      vst[dx][dy - 1] = 1;
      temp = max(temp, d[dx][dy - 1]);
      q.push(make_pair(dx, dy - 1));
    }
  }
  ans = max(ans, temp);
}
int main() {
  read(n), read(m);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (c[i][j] == '.') {
        memset(vst, 0, sizeof(vst));
        memset(d, 0, sizeof(d));
        BFS(i, j);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
