#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long n, long long m) { return (m ? gcd(m, n % m) : n); }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
long long mod = 1000000007;
long long fac[1000010];
long long modinv(long long a) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}
void modfac() {
  fac[0] = 1;
  for (long long i = 1; i < 1000010; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
}
long long modperm(long long n, long long k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  else
    return (fac[n] * modinv(fac[n - k])) % mod;
}
long long modcomb(long long n, long long k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  else
    return ((fac[n] * modinv(fac[k])) % mod * modinv(fac[n - k])) % mod;
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> a[i][j];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '.') {
        vector<vector<int>> cnt(h, vector<int>(w));
        vector<vector<bool>> flag(h, vector<bool>(w));
        queue<pair<long long, long long>> que;
        que.push(pair<long long, long long>(i, j));
        while (!que.empty()) {
          pair<long long, long long> p = que.front();
          que.pop();
          for (int x = 0; x < 4; x++) {
            if (0 <= p.first + dx[x] && p.first + dx[x] < h &&
                0 <= p.second + dy[x] && p.second + dy[x] < w &&
                a[p.first + dx[x]][p.second + dy[x]] == '.' &&
                !flag[p.first + dx[x]][p.second + dy[x]]) {
              cnt[p.first + dx[x]][p.second + dy[x]] =
                  cnt[p.first][p.second] + 1;
              flag[p.first + dx[x]][p.second + dy[x]] = true;
              que.push(pair<long long, long long>(p.first + dx[x],
                                                  p.second + dy[x]));
            }
          }
        }
        int dis = 0;
        for (int x = 0; x < h; x++) {
          for (int y = 0; y < w; y++) {
            chmax(dis, cnt[x][y]);
          }
        }
        chmax(ans, dis);
      }
    }
  }
  cout << ans << endl;
}
