#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};
int h, w;
tuple<int, int, int> bfs(const vector<string> &s, int x, int y) {
  vector<vector<int>> d(h, vector<int>(w, -INF));
  queue<P> q;
  q.push(make_pair(x, y));
  d[x][y] = 0;
  int ma = 0;
  while (!q.empty()) {
    int xi = q.front().first;
    int yi = q.front().second;
    q.pop();
    for (int i = 0; i < (int)(4); i++) {
      int nx = xi + dx[i];
      int ny = yi + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && d[nx][ny] == -INF &&
          s[nx][ny] == '.') {
        q.push(make_pair(nx, ny));
        d[nx][ny] = d[xi][yi] + 1;
        ma = max(ma, d[nx][ny]);
      }
    }
  }
  P res;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (d[i][j] == ma) res = make_pair(i, j);
    }
  }
  return make_tuple(ma, res.first, res.second);
}
int main() {
  cin >> h >> w;
  vector<string> m(h);
  for (int i = 0; i < (int)(h); i++) cin >> m[i];
  tuple<int, int, int> s = bfs(m, 0, 0);
  int a, b, c;
  tie(a, b, c) = s;
  s = bfs(m, b, c);
  tie(a, b, c) = s;
  cout << a << endl;
}
