#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  gcd(b, a % b);
}
char maze[25][25];
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
long long r, c;
long long vis[25][25];
long long ii, jj;
pair<pair<long long, long long>, long long> bfs(long long x, long long y) {
  long long dist[25][25];
  memset(dist, -1, sizeof(dist));
  dist[x][y] = 0;
  queue<pair<long long, long long> > q;
  q.push({x, y});
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    x = p.first;
    y = p.second;
    for (long long i = 0; i < 4; i++) {
      long long tx = x + dx[i];
      long long ty = y + dy[i];
      if (tx <= r && tx >= 1 && ty <= c && ty >= 1 && dist[tx][ty] == -1 &&
          maze[tx][ty] == '.') {
        q.push({tx, ty});
        dist[tx][ty] = dist[x][y] + 1;
      }
    }
  }
  long long mx = 0;
  pair<long long, long long> idx;
  for (long long i = 1; i <= r; i++) {
    for (long long j = 1; j <= c; j++) {
      if (maze[i][j] == '.') {
        if (dist[i][j] > mx) {
          mx = dist[i][j];
          idx.first = i;
          idx.second = j;
        }
      }
    }
  }
  return {idx, mx};
}
void find() {
  pair<pair<long long, long long>, long long> t1, t2;
  t1 = bfs(ii, jj);
  t2 = bfs(t1.first.first, t1.first.second);
  cout << t2.second << endl;
}
void solve() {
  cin >> r >> c;
  bool flag = true;
  for (long long i = 1; i <= r; i++) {
    for (long long j = 1; j <= c; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == '.' && flag) {
        ii = i, jj = j;
      }
    }
  }
  find();
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
