#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int c = power(a, b / 2, m);
  if (b % 2 == 0) return ((c % m) * (c % m)) % m;
  return ((((c % m) * (c % m)) % m) * (a % m)) % m;
}
long long int n, m, vis[21][21], dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
string s[21];
void bfs(long long int xx, long long int yy, long long int h) {
  queue<pair<long long int, long long int> > qu;
  long long int x, y;
  vis[xx][yy] = 1;
  qu.push({xx, yy});
  while (!qu.empty()) {
    x = qu.front().first;
    y = qu.front().second;
    qu.pop();
    for (long long int i = 0; i < 4; i++) {
      long long int p = x + dx[i], q = y + dy[i];
      if (p >= 0 && p < n && q >= 0 && q < m && s[p][q] != '#' && !vis[p][q]) {
        qu.push({p, q});
        vis[p][q] = vis[x][y] + 1;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int k, i, j, c = 0, cs = 0, t;
  t = 1;
  while (t--) {
    cin >> n >> m;
    long long int p = 0, q = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> s[i];
      if (s[p][q] != '.') {
        for (long long int j = 0; j < m; j++) {
          if (s[i][j] == '.') {
            p = i, q = j;
            break;
          }
        }
      }
    }
    memset(vis, 0, sizeof vis);
    bfs(p, q, 1);
    k = 0;
    p = 0, q = 0;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (k < vis[i][j] && s[i][j] != '#') {
          k = vis[i][j];
          p = i;
          q = j;
        }
      }
    }
    memset(vis, 0, sizeof vis);
    bfs(p, q, 1);
    k = 0;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (k < vis[i][j] && s[i][j] != '#') {
          k = vis[i][j];
          p = i;
          q = j;
        }
      }
    }
    cout << k - 1;
    cout << "\n";
  }
  return 0;
}
