#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> maze(h);
  for (int i = 0; i < (h); ++i) cin >> maze[i];
  int ans = 0;
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (maze[i][j] == '#') continue;
      queue<pair<int, int>> q;
      vector<vector<int>> d(h, vector<int>(w, INF));
      q.push(make_pair(i, j));
      d[i][j] = 0;
      auto update = [&](int i, int j, int x) {
        if (d[i][j] == INF) return;
        d[i][j] = x;
        q.push(pair<int, int>(i, j));
      };
      update(i, j, 0);
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          int ni = dy[k] + p.first;
          int nj = dx[k] + p.second;
          if (0 > ni && ni >= h && 0 > nj && nj >= w) continue;
          if (maze[ni][nj] != '#') continue;
          update(ni, nj, d[p.first][p.second] + 1);
        }
      }
      for (int y = 0; y < (h); ++y)
        for (int x = 0; x < (w); ++x) {
          if (d[y][x] == INF) continue;
          ans = max(ans, d[y][x]);
        }
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
