#include <bits/stdc++.h>
using namespace std;
using vii = vector<vector<int>>;
using vi = vector<int>;
vii dist;
vi dx = {1, 0, -1, 0};
vi dy = {0, -1, 0, 1};
int h, w;
vector<string> s;
int dfs(int i, int j, int d = 0) {
  dist[i][j] = d;
  int ni, nj;
  for (int k = 0; k < (4); k++) {
    ni = i + dx[k];
    nj = j + dy[k];
    if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
    if (s[ni][nj] == '#') continue;
    if (dist[ni][nj] != 0 && dist[ni][nj] <= d + 1) continue;
    dfs(ni, nj, d + 1);
  }
  return 0;
}
int main() {
  cin >> h >> w;
  s = vector<string>(h);
  for (int i = 0; i < (h); i++) {
    cin >> s.at(i);
  }
  dist = vii(h, vi(w, 0));
  int ans = 0;
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      if (s[i][j] != '#') {
        dist = vii(h, vi(w, 0));
        dfs(i, j);
        int tans = 0;
        for (int ti = 0; ti < (h); ti++) {
          for (int tj = 0; tj < (w); tj++) {
            tans = max(tans, dist[ti][tj]);
          }
        }
        ans = max(tans, ans);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
