#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h, "");
  for (int i = 0; i < (int)(h); i++) {
    cin >> s[i];
  }
  vector<vector<int> > dp(h * w, vector<int>(h * w, 1e9));
  for (int i = 0; i < (int)(h * w); i++) {
    int x = i % w;
    int y = i / w;
    if (s[y][x] == '#') {
      continue;
    }
    if (x != 0 && s[y][x - 1] == '.') {
      dp[i][i - 1] = 1;
    }
    if (y != 0 && s[y - 1][x] == '.') {
      dp[i][i - w] = 1;
    }
    if (x != w - 1 && s[y][x + 1] == '.') {
      dp[i][i + 1] = 1;
    }
    if (y != h - 1 && s[y + 1][x] == '.') {
      dp[i][i + w] = 1;
    }
  }
  for (int k = 0; k < (int)(h * w); k++) {
    for (int i = 0; i < (int)(h * w); i++) {
      for (int j = 0; j < (int)(h * w); j++) {
        if (dp[i][j] > dp[i][k] + dp[k][j]) {
          dp[i][j] = dp[i][k] + dp[k][j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(h * w); i++) {
    for (int j = 0; j < (int)(h * w); j++) {
      if (s[i / w][i % w] != '#' && s[j / w][j % w] != '#') {
        ans = max(ans, dp[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
