#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long jou(long long N, long long P) {
  if (P == 0) return 1;
  if (P % 2 == 0) {
    long long t = jou(N, P / 2);
    return t * t % 1000000007;
  }
  return (N * jou(N, P - 1)) % 1000000007;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int r, c, sx, sy;
  cin >> r >> c;
  vector<string> p(r);
  for (int i = 0; i < (int)(r); i++) {
    cin >> p[i];
    for (int j = 0; j < (int)(c); j++) {
      if (p[i][j] == '.') {
        sx = i;
        sy = j;
      }
    }
  }
  vector<vector<int>> dist(r, vector<int>(c, -1));
  queue<pair<int, int>> que;
  dist[sx][sy] = 0;
  pair<int, int> q = make_pair(sx, sy);
  que.push(q);
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (int i = 0; i < (int)(4); i++) {
      int nh = v.first + dx[i];
      int nw = v.second + dy[i];
      if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue;
      if (p[nh][nw] == '#') continue;
      if (dist[nh][nw] != -1) continue;
      dist[nh][nw] = dist[v.first][v.second] + 1;
      pair<int, int> r = make_pair(nh, nw);
      que.push(r);
    }
  }
  int dai, nx, ny;
  dai = 0;
  for (int i = 0; i < (int)(r); i++) {
    for (int j = 0; j < (int)(c); j++) {
      if (dai < dist[i][j]) {
        nx = i;
        ny = j;
      }
      dai = max(dai, dist[i][j]);
    }
  }
  for (int i = 0; i < (int)(r); i++) {
    for (int j = 0; j < (int)(c); j++) {
      dist[i][j] = -1;
    }
  }
  dist[nx][ny] = 0;
  q = make_pair(nx, ny);
  que.push(q);
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (int i = 0; i < (int)(4); i++) {
      int nh = v.first + dx[i];
      int nw = v.second + dy[i];
      if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue;
      if (p[nh][nw] == '#') continue;
      if (dist[nh][nw] != -1) continue;
      dist[nh][nw] = dist[v.first][v.second] + 1;
      pair<int, int> r = make_pair(nh, nw);
      que.push(r);
    }
  }
  dai = 0;
  for (int i = 0; i < (int)(r); i++) {
    for (int j = 0; j < (int)(c); j++) {
      dai = max(dai, dist[i][j]);
    }
  }
  cout << dai << endl;
}
