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