#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> s;
vector<vector<bool> > used;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, 1, -1, 0};
int bfs(int x, int y) {
  queue<pair<pair<int, int>, int> > q;
  q.push({{x, y}, 0});
  int res = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int ex = p.first.first, ey = p.first.second;
    res = max(res, p.second);
    used[ex][ey] = true;
    for (int i = 0; i < 4; ++i) {
      int nx = ex + dx[i], ny = ey + dy[i];
      if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
      if (s[nx][ny] == '#') continue;
      if (used[nx][ny]) continue;
      q.push({{nx, ny}, p.second + 1});
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      used.assign(h, vector<bool>(w, false));
      if (s[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
