#include <bits/stdc++.h>
using namespace std;
long long fast_pow(long long x, long long y, long long p);
long long n, m;
char a[21][21];
long long bfs(long long sx, long long sy) {
  queue<pair<long long, long long>> q;
  q.push({sx, sy});
  long long count = 0;
  bool visited[n][m];
  memset(visited, 0, sizeof(visited));
  long long matrix[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) matrix[i][j] = INT_MAX;
  matrix[sx][sy] = 0;
  long long mx = 0;
  while (!q.empty()) {
    long long size = q.size();
    for (long long i = 0; i < size; i++) {
      pair<long long, long long> x = q.front();
      q.pop();
      sx = x.first;
      sy = x.second;
      visited[sx][sy] = 1;
      matrix[sx][sy] = min(matrix[sx][sy], count);
      mx = max(mx, matrix[sx][sy]);
      if (sx + 1 < n && !visited[sx + 1][sy] && a[sx + 1][sy] != '#') {
        q.push({sx + 1, sy});
      }
      if (sx - 1 >= 0 && !visited[sx - 1][sy] && a[sx - 1][sy] != '#') {
        q.push({sx - 1, sy});
      }
      if (sy + 1 < m && !visited[sx][sy + 1] && a[sx][sy + 1] != '#') {
        q.push({sx, sy + 1});
      }
      if (sy - 1 >= 0 && !visited[sx][sy - 1] && a[sx][sy - 1] != '#') {
        q.push({sx, sy - 1});
      }
    }
    count++;
  }
  return mx;
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        ans = max(ans, bfs(i, j));
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
long long fast_pow(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
