#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long N = 2e5 + 5;
const long double pi = 3.14159265359;
long long n, m, ans, dis[25][25];
char u[25][25];
queue<pair<long long, long long> > q;
long long dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
long long f(long long x, long long y) {
  long long tmp = 0;
  memset(dis, -1, sizeof(dis));
  dis[x][y] = 0;
  while ((long long)q.size()) q.pop();
  q.push(make_pair(x, y));
  while ((long long)q.size()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (long long j = 0; j < 4; j++) {
      if (x + dx[j] > n || y + dy[j] > m || x + dx[j] < 1 || y + dy[j] < 1)
        continue;
      if (u[x + dx[j]][y + dy[j]] == '#') continue;
      if (dis[x + dx[j]][y + dy[j]] != -1) continue;
      dis[x + dx[j]][y + dy[j]] = dis[x][y] + 1;
      q.push(make_pair(x + dx[j], y + dy[j]));
    }
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) tmp = max(tmp, dis[i][j]);
  return tmp;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> u[i][j];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      ans = max(ans, f(i, j));
    }
  cout << ans << "\n";
  return 0;
}
