#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1000000007;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void warshal_floyd(vector<vector<long long>>& dist) {
  int V = dist.size();
  for (int k = 0; k < (V); ++k) {
    for (int i = 0; i < (V); ++i) {
      for (int j = 0; j < (V); ++j) {
        if (dist[i][k] != LINF && dist[k][j] != LINF)
          chmin(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      cin >> S[i][j];
    }
  }
  int V, E;
  V = H * W;
  vector<vector<long long>> dist(V, vector<long long>(V, INF));
  for (int i = 0; i < (V); ++i) {
    dist[i][i] = 0;
  }
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      if (j + 1 < W && S[i][j] == '.' && S[i][j + 1] == '.') {
        dist[i * H + j][i * H + (j + 1)] = 1;
        dist[i * H + (j + 1)][i * H + j] = 1;
      }
      if (i + 1 < H && S[i][j] == '.' && S[i + 1][j] == '.') {
        dist[i * H + j][(i + 1) * H + j] = 1;
        dist[(i + 1) * H + j][i * H + j] = 1;
      }
    }
  }
  warshal_floyd(dist);
  long long ans = 0;
  for (int i = 0; i < (V); ++i) {
    for (int j = 0; j < (V); ++j) {
      if (dist[i][j] >= INF) continue;
      chmax(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
}
