#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int diff[4][2] = {
    {0, -1},
    {-1, 0},
    {1, 0},
    {0, 1},
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int maze[22][22] = {{}};
  for (int i = 1; i <= h; i++) {
    string tmp;
    cin >> tmp;
    for (int j = 1; j <= w; j++) {
      if (tmp[j - 1] == '.') {
        maze[i][j] = 1;
      } else {
        maze[i][j] = 2;
      }
    }
  }
  int V = (w + 1) * (h + 1);
  vector<vector<int>> G(V, vector<int>(V, inf));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (maze[i][j] == 1) {
        for (int k = 0; k < 4; k++) {
          if (maze[i + diff[k][0]][j + diff[k][1]] == 1) {
            G[(i - 1) * w + j][((i - 1) + diff[k][0]) * w + j + diff[k][1]] = 1;
            G[((i - 1) + diff[k][0]) * w + j + diff[k][1]][(i - 1) * w + j] = 1;
          }
        }
      }
    }
  }
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (G[i][j] < inf) {
        ans = max(ans, G[i][j]);
      }
    }
  }
  cout << ans << "\n";
}
