#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LLINF = 1e18;
const long long MOD = 1e9 + 7;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int MAX = 500;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int g[MAX][MAX];
int h, w;
vector<string> s;
int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; i++) cin >> s[i];
  auto id = [&](int x, int y) { return y * h + x; };
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) g[i][j] = (i == j) ? 0 : 100000;
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (s[y][x] == '#') continue;
      for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
        if (s[ny][nx] == '#') continue;
        g[id(x, y)][id(nx, ny)] = 1;
        g[id(nx, ny)][id(x, y)] = 1;
      }
    }
  }
  int v = h * w;
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        chmin(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  int ans = -1;
  for (int y1 = 0; y1 < h; y1++) {
    for (int x1 = 0; x1 < w; x1++) {
      if (s[y1][x1] == '#') continue;
      for (int y2 = 0; y2 < h; y2++) {
        for (int x2 = 0; x2 < w; x2++) {
          if (s[y2][x2] == '#') continue;
          chmax(ans, g[id(x1, y1)][id(x2, y2)]);
        }
      }
    }
  }
  cout << ans << endl;
}
