#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
char f[25][25];
int h, w;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool rn(int x, int y) { return 0 <= x && x < h && y >= 0 && y < w; }
int calc(int sx, int sy, int gx, int gy) {
  lli dp[25][25] = {};
  dp[sx][sy] = 1;
  queue<pair<pair<int, int>, int>> que;
  que.push(make_pair(make_pair(sx, sy), 0));
  while (!que.empty()) {
    int d = que.front().second;
    pair<int, int> s = que.front().first;
    if (s.first == gx && s.second == gy) return d;
    dp[s.first][s.second] = 1;
    que.pop();
    for (lli i = 0; i < (4); i++) {
      int nx = dx[i] + s.first;
      int ny = dy[i] + s.second;
      if (rn(nx, ny) && f[nx][ny] == '.') {
        if (!dp[nx][ny]) que.push(make_pair(make_pair(nx, ny), d + 1));
      }
    }
  }
  return 1e7;
}
int main() {
  cin >> h >> w;
  for (lli i = 0; i < (h); i++)
    for (lli j = 0; j < (w); j++) cin >> f[i][j];
  int ans = 0;
  for (lli sx = 0; sx < (h); sx++)
    for (lli sy = 0; sy < (w); sy++)
      for (lli gx = 0; gx < (h); gx++)
        for (lli gy = 0; gy < (w); gy++) {
          int tmp = calc(sx, sy, gx, gy);
          if (tmp != 1e7) ans = max(ans, tmp);
        }
  cout << ans << endl;
  return 0;
}
