#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, -1, 0, 1};
int h, w;
int mx_depth = 0;
int dfs(int y, int x, int depth, vector<vector<int>> seen, vector<string> s) {
  int temp = 0;
  for (int i = 0; i < 4; i++) {
    int ny = y + dy.at(i);
    int nx = x + dx.at(i);
    if (ny < 0 || ny > h - 1 || nx < 0 || nx > w - 1) continue;
    if (seen.at(ny).at(nx) != inf || s.at(ny).at(nx) == '#') continue;
    seen.at(ny).at(nx) = min(depth++, seen.at(ny).at(nx));
    mx_depth = max(mx_depth, depth);
    dfs(nx, ny, depth++, seen, s);
  }
  for (int k = 0; k < (h); k++) {
    for (int l = 0; l < (w); l++) {
      if (seen.at(k).at(l) == inf) continue;
      temp = max(temp, seen.at(k).at(l));
    }
  }
  return temp;
}
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); i++) cin >> s.at(i);
  int ans = 0;
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      vector<vector<int>> seen(h, vector<int>(w, inf));
      seen.at(i).at(j) = 0;
      ans = max(ans, dfs(i, j, 0, seen, s));
    }
  }
  cout << ans << endl;
}
