#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000007;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> maze(h);
  for (int i = 0; i < h; i++) {
    cin >> maze.at(i);
  }
  int ans = -1;
  for (int sx = 0; sx < w; sx++) {
    for (int sy = 0; sy < h; sy++) {
      for (int tx = 0; tx < w; tx++) {
        for (int ty = 0; ty < h; ty++) {
          vector<vector<int>> dist(h, vector<int>(w, -1));
          dist.at(sy).at(sx) = 0;
          queue<pair<int, int>> que;
          que.push(make_pair(sx, sy));
          while (!que.empty()) {
            int x = que.front().first;
            int y = que.front().second;
            que.pop();
            if (x == tx && y == ty) {
              ans = max(ans, dist.at(y).at(x));
              break;
            }
            vector<int> dx = {1, 0, 0, -1}, dy = {0, -1, 1, 0};
            for (int i = 0; i < 4; i++) {
              int px = x + dx.at(i);
              int py = y + dy.at(i);
              if (px < 0 || px >= w || py < 0 || py >= h ||
                  maze.at(py).at(px) == '#' || dist.at(py).at(px) != -1)
                continue;
              dist.at(py).at(px) = dist.at(y).at(x) + 1;
              que.push(make_pair(px, py));
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
