#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
long long dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long long maxn = 1e5;
const long long OO = 100;
const long long mod = 1e9 + 7;
const long double PI = acos(-1);
void maxself(long long &a, long long b) { a = max(a, b); }
void minself(long long &a, long long b) { a = min(a, b); }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long ind = 1;
  char ma[n][m];
  long long num[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> ma[i][j], num[i][j] = ind++;
  long long dist[ind][ind];
  for (long long i = 0; i < ind; i++)
    for (long long j = 0; j < ind; j++) dist[i][j] = OO;
  for (long long i = 0; i < ind; i++) dist[i][i] = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (ma[i][j] == '#') continue;
      if (i > 0 and ma[i - 1][j] == '.') dist[num[i][j]][num[i - 1][j]] = 1;
      if (j > 0 and ma[i][j - 1] == '.') dist[num[i][j]][num[i][j - 1]] = 1;
      if (j + 1 < m and ma[i][j + 1] == '.') dist[num[i][j]][num[i][j + 1]] = 1;
      if (i + 1 < n and ma[i + 1][j] == '.') dist[num[i][j]][num[i + 1][j]] = 1;
    }
  }
  for (long long i = 1; i < ind; i++)
    for (long long j = 1; j < ind; j++)
      for (long long k = 1; k < ind; k++)
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
  long long sol = 0;
  for (long long i = 1; i < ind; i++)
    for (long long j = 1; j < ind; j++)
      if (dist[i][j] != OO) sol = max(sol, dist[i][j]);
  cout << sol;
  return 0;
}
