#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
const int N = 25;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int h, w;
char a[N][N];
int f[N * N][N * N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> w;
  for (int i = (1); i <= (20 * 20); i++)
    for (int j = (1); j <= (20 * 20); j++) f[i][j] = INF;
  for (int i = (1); i <= (h); i++)
    for (int j = (1); j <= (w); j++) cin >> a[i][j];
  int m = h * w;
  for (int i = (1); i <= (h); i++)
    for (int j = (1); j <= (w); j++) {
      if (a[i][j] == '#') continue;
      int pos = (i - 1) * w + j;
      if (a[i][j + 1] == '.' && j + 1 <= w) {
        f[pos][pos + 1] = 1;
        f[pos + 1][pos] = 1;
      }
      if (a[i + 1][j] == '.' && i + 1 <= h) {
        f[pos + w][pos] = 1;
        f[pos][pos + w] = 1;
      }
    }
  int ma = 0;
  pair<int, int> pos;
  for (int k = (1); k <= (m); k++)
    for (int i = (1); i <= (m); i++)
      for (int j = (1); j <= (m); j++)
        if (f[i][j] > f[i][k] + f[k][j]) {
          f[i][j] = f[i][k] + f[k][j];
        }
  for (int i = (1); i <= (m); i++) {
    for (int j = (1); j <= (m); j++) {
      if (f[i][j] != INF) ma = max(ma, f[i][j]);
    }
  }
  cout << ma;
  return 0;
}
