#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; ++i) {
    cin >> grid[i];
  }
  int ans = 0;
  for (int i = 0; i < h * w; ++i) {
    for (int j = 0; j < h * w; ++j) {
      int sx = i % w;
      int sy = i / w;
      int gx = j % w;
      int gy = j / w;
      vector<vector<int>> d(h, vector<int>(w, inf));
      d[sy][sx] = 0;
      queue<pair<int, int>> que;
      que.push(make_pair(sy, sx));
      pair<int, int> dir[] = {
          {1, 0},
          {0, 1},
          {-1, 0},
          {0, -1},
      };
      while (!que.empty()) {
        auto p = que.front();
        que.pop();
        for (const auto& e : dir) {
          int toy = e.first + p.first;
          int tox = e.second + p.second;
          if (0 <= toy && toy < h && 0 <= tox && tox < w &&
              d[toy][tox] == inf && grid[toy][tox] != '#') {
            d[toy][tox] = d[p.first][p.second] + 1;
            que.push(make_pair(toy, tox));
          }
        }
      }
      if (d[gy][gx] != inf) ans = max(ans, d[gy][gx]);
    }
  }
  cout << ans << endl;
  return 0;
}
