#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int mod = 1e9 + 7;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  vector<vector<int>> adj(h * w, vector<int>(h * w, inf));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#') continue;
      int a = (i - 1) * h + (j - 1);
      for (int d = 0; d < 4; d++) {
        int ni = i + dx[d], nj = j + dy[d];
        int b = (ni - 1) * h + (nj - 1);
        if (s[ni][nj] == '.') {
          adj[a][b] = adj[b][a] = 1;
        }
      }
    }
  }
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (adj[i][j] != inf) {
        ans = max(ans, adj[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
