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