#include <bits/stdc++.h>
using namespace std;
char a[21][21];
long long n, m;
long long d[21][21];
long long dx[] = {0, 0, -1, 1};
long long dy[] = {1, -1, 0, 0};
long long res = -2e18;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  long long posx, posy;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') posx = i, posy = j;
    }
  memset(d, -1, sizeof(d));
  queue<long long> q;
  q.push(posx);
  q.push(posy);
  d[posx][posy] = 0;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    long long y = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long nx = x + dx[i];
      long long ny = y + dy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (a[nx][ny] == '.' && d[nx][ny] == -1) {
        d[nx][ny] = d[x][y] + 1;
        q.push(nx);
        q.push(ny);
      }
    }
  }
  long long x, y;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      if (d[i][j] > res) {
        res = d[i][j];
        x = i;
        y = j;
      }
  memset(d, -1, sizeof(d));
  q.push(x);
  q.push(y);
  d[x][y] = 0;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    y = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long nx = x + dx[i];
      long long ny = y + dy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m || a[nx][ny] != '.') continue;
      if (d[nx][ny] == -1) {
        d[nx][ny] = d[x][y] + 1;
        q.push(nx);
        q.push(ny);
      }
    }
  }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) res = max(res, d[i][j]);
  cout << res << endl;
  return 0;
}
