#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> m(h);
  for (int i = 0; i < h; ++i) {
    cin >> m[i];
  }
  int ans = 0;
  vector<int> vy = {-1, 0, 1, 0};
  vector<int> vx = {0, 1, 0, -1};
  for (int sy = 0; sy < h; ++sy) {
    for (int sx = 0; sx < w; ++sx) {
      for (int gy = 0; gy < h; ++gy) {
        for (int gx = 0; gx < w; ++gx) {
          queue<pair<pair<int, int>, int>> q;
          q.push(make_pair(make_pair(sy, sx), 0));
          vector<vector<bool>> visited(h, vector<bool>(w, false));
          pair<int, int> g(gy, gx);
          while (!q.empty()) {
            auto t = q.front();
            if (t.first == g) break;
            q.pop();
            for (int i = 0; i < 4; ++i) {
              int ny, nx;
              ny = t.first.first + vy[i];
              nx = t.first.second + vx[i];
              if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
              if (m[ny][nx] == '#') continue;
              if (visited[ny][nx]) continue;
              visited[ny][nx] = true;
              q.push(make_pair(make_pair(ny, nx), t.second + 1));
            }
          }
          ans = max(ans, q.front().second);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
