#include <bits/stdc++.h>
using namespace std;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
long long mod = 1000000007;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) cin >> s[i][j];
  }
  int ans = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (s[i][j] == '#') continue;
      queue<pair<int, int>> list;
      vector<vector<int>> dist(h, vector<int>(w, INF));
      list.emplace(i, j);
      dist[i][j] = 0;
      while (!list.empty()) {
        int i_ = list.front().first;
        int j_ = list.front().second;
        list.pop();
        int x = dist[i_][j_];
        for (int dir = 0; dir < (int)(4); dir++) {
          int nx = i_ + dx[dir];
          int ny = j_ + dy[dir];
          if (nx < 0 || nx >= w) continue;
          if (ny < 0 || ny >= h) continue;
          if (s[nx][ny] == '#') continue;
          if (dist[nx][ny] != INF) continue;
          list.emplace(nx, ny);
          dist[nx][ny] = x + 1;
        }
      }
      for (int _i = 0; _i < (int)(h); _i++) {
        for (int _j = 0; _j < (int)(w); _j++) {
          if (dist[_i][_j] == INF) continue;
          ans = max(ans, dist[_i][_j]);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
