#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;
long long dp[100005];
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      if (s[sy][sx] == '#') continue;
      for (int gy = 0; gy < h; gy++) {
        for (int gx = 0; gx < w; gx++) {
          if (s[gy][gx] == '#') continue;
          queue<pair<pair<int, int>, int> > que;
          que.push(make_pair(make_pair(sx, sy), 0));
          while (!que.empty()) {
            pair<pair<int, int>, int> tmp = que.front();
            que.pop();
            int cnt = tmp.second;
            if (tmp.first.first == gx && tmp.first.second == gy) {
              ans = max(ans, cnt);
              break;
            }
            for (int i = 0; i < 4; i++) {
              int nx = tmp.first.first + dx[i];
              int ny = tmp.first.second + dy[i];
              if (nx >= 0 && nx < w && ny >= 0 && ny < h && s[ny][nx] == '.') {
                que.push(make_pair(make_pair(nx, ny), cnt + 1));
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
