#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9 + 10;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long N = n * m;
  vector<vector<long long> > dp(N, vector<long long>(N, inf));
  vector<string> in(n);
  for (long long i = 0; i < n; i++) cin >> in[i];
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++)
      if (i - j) {
        long long x1 = i / m, y1 = i % m, x2 = j / m, y2 = j % m;
        if (abs(x1 - x2) + abs(y1 - y2) - 1) continue;
        if (in[x1][y1] == in[x2][y2] && in[x1][y1] == '.')
          dp[i][j] = dp[j][i] = 1;
      }
  for (long long k = 0; k < N; k++)
    for (long long i = 0; i < N; i++)
      for (long long j = 0; j < N; j++) cmin(dp[i][j], dp[i][k] + dp[k][j]);
  long long out = 0;
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++)
      if (dp[i][j] - inf) cmax(out, dp[i][j]);
  cout << out << endl;
}
