#include <bits/stdc++.h>
using namespace std;
long modpow(long a, long n, long mod) {
  long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long modinv(long a, long mod) { return modpow(a, mod - 2, mod); }
int main() {
  int H, W;
  char map[25][25];
  int d[25][25];
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans, temp, x, y;
  cin >> H >> W;
  for (int i = 0; (i) < (H); (i)++)
    for (int j = 0; (j) < (W); (j)++) cin >> map[i][j];
  ans = 0;
  for (int i = 0; (i) < (H); (i)++)
    for (int j = 0; (j) < (W); (j)++) {
      for (int k = 0; (k) < (H); (k)++)
        for (int l = 0; (l) < (W); (l)++) d[k][l] = -1;
      queue<pair<int, int> > now;
      now.push(make_pair(i, j));
      d[i][j] = 0;
      while (!now.empty()) {
        pair<int, int> p = now.front();
        x = p.first;
        y = p.second;
        now.pop();
        for (int k = 0; (k) < (4); (k)++) {
          if (x + dx[k] >= 0 && x + dx[k] < H && y + dy[k] >= 0 &&
              y + dy[k] < W && map[x + dx[k]][y + dy[k]] == '.' &&
              d[x + dx[k]][y + dy[k]] == -1) {
            now.push(make_pair(x + dx[k], y + dy[k]));
            d[x + dx[k]][y + dy[k]] = d[x][y] + 1;
          }
        }
      }
      temp = 0;
      for (int k = 0; (k) < (H); (k)++)
        for (int l = 0; (l) < (W); (l)++)
          if (temp < d[k][l]) temp = d[k][l];
      if (ans < temp) ans = temp;
    }
  cout << ans << endl;
  return 0;
}
