#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); ++i) cin >> S[i];
  int ans = 0;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      if (S[i][j] == '#') continue;
      vector<vector<int>> dist(H, vector<int>(W, 1e+3));
      dist[i][j] = 0;
      queue<pair<int, int>> q;
      q.push({i, j});
      while (!q.empty()) {
        auto tmp = q.front();
        q.pop();
        int x = tmp.first;
        int y = tmp.second;
        vector<pair<int, int>> next = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
        for (auto n : next) {
          int nx = x + n.first;
          int ny = y + n.second;
          if (0 <= nx and ny < H and 0 <= nx and ny < W and S[nx][ny] == '.') {
            if (dist[nx][ny] > dist[x][y] + 1) {
              dist[nx][ny] = dist[x][y] + 1;
              q.push({nx, ny});
            }
          }
        }
      }
      for (int k = 0; k < (int)(H); ++k) {
        for (int l = 0; l < (int)(W); ++l) {
          if (dist[k][l] != 1e+3) ans = max(ans, dist[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
