#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  for (int i = 1; i <= t; ++i) solve();
  cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}
const int N = 500 + 2;
long long d[N][N];
int n;
void FloydWarshall() {
  for (int k = 1; k < n; ++k) {
    for (int i = 1; i < n; ++i) {
      for (int j = 1; j < n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
void solve() {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      d[i][j] = 1e6;
    }
  }
  int h, w;
  cin >> h >> w;
  char arr[h + 1][w + 1];
  for (int i = 1; i < h + 1; ++i) {
    for (int j = 1; j < w + 1; ++j) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i < h + 1; ++i) {
    for (int j = 1; j < w + 1; ++j) {
      if (i - 1 > 0 and arr[i][j] == arr[i - 1][j] and arr[i][j] == '.') {
        int a = (i - 2) * w + j;
        int b = (i - 1) * w + j;
        d[a][b] = 1;
        d[b][a] = 1;
      }
      if (j - 1 > 0 and arr[i][j] == arr[i][j - 1] and arr[i][j] == '.') {
        int a = (i - 1) * w + j - 1;
        int b = (i - 1) * w + j;
        d[a][b] = 1;
        d[b][a] = 1;
      }
    }
  }
  n = h * w + 1;
  FloydWarshall();
  long long out = -1;
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < n; ++j) {
      if (d[i][j] == (long long)(1e6)) continue;
      out = max(out, d[i][j]);
    }
  }
  cout << out << '\n';
}
