#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
void WarshallFloyd(int N, vector<vector<ll>> &dist) {
  for (int k = (int)(0); k < (int)(N); k++)
    for (int i = (int)(0); i < (int)(N); i++) {
      if (dist[i][k] == (long long)4e18) continue;
      for (int j = (int)(0); j < (int)(N); j++) {
        if (dist[k][j] == (long long)4e18) continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  vector<vector<ll>> dist(H * W, vector<ll>(H * W, (long long)4e18));
  for (int i = (int)(0); i < (int)(H); i++) {
    cin >> S[i];
  }
  int dh[] = {0, 1, -1, 0};
  int dw[] = {1, 0, 0, -1};
  for (int i = (int)(0); i < (int)(H); i++)
    for (int j = (int)(0); j < (int)(W); j++) {
      for (int k = (int)(0); k < (int)(4); k++) {
        if (i + dh[k] >= 0 && i + dh[k] < H && j + dw[k] >= 0 &&
            j + dw[k] < W) {
          if (S[i][j] == '.' && S[i + dh[k]][j + dw[k]] == '.') {
            dist[W * i + j][W * (i + dh[k]) + j + dw[k]] = 1;
            dist[W * (i + dh[k]) + j + dw[k]][W * i + j] = 1;
          }
        }
      }
    }
  WarshallFloyd(H * W, dist);
  ll ans = 0;
  for (int i = (int)(0); i < (int)(H * W); i++)
    for (int j = (int)(0); j < (int)(H * W); j++) {
      if (dist[i][j] != (long long)4e18) ans = max(ans, dist[i][j]);
    }
  cout << ans << endl;
}
