#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int d[h][w];
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) d[i][j] = 200000009;
  vector<string> vs(h);
  for (int i = (0); i < (h); ++i) cin >> vs[i];
  int sh, sw;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) {
      if (vs[i][j] == '.') {
        sh = i;
        sw = j;
        break;
      }
    }
  bool c[h][w];
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) c[i][j] = false;
  queue<pair<int, int>> q;
  q.push(make_pair((sh), (sw)));
  c[sh][sw] = true;
  d[sh][sw] = 0;
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  while (!q.empty()) {
    int th = q.front().first;
    int tw = q.front().second;
    q.pop();
    for (int i = (0); i < (4); ++i) {
      if (th + dy[i] < h && th + dy[i] >= 0 && tw + dx[i] < w &&
          tw + dx[i] >= 0 && vs[th + dy[i]][tw + dx[i]] == '.' &&
          !c[th + dy[i]][tw + dx[i]]) {
        d[th + dy[i]][tw + dx[i]] = d[th][tw] + 1;
        c[th + dy[i]][tw + dx[i]] = true;
        q.push(make_pair((th + dy[i]), (tw + dx[i])));
      }
    }
  }
  int ma = -1;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) {
      if (ma < d[i][j] && d[i][j] != 200000009) {
        sh = i;
        sw = j;
        ma = d[i][j];
      }
    }
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) d[i][j] = 200000009;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) c[i][j] = false;
  q.push(make_pair((sh), (sw)));
  c[sh][sw] = true;
  d[sh][sw] = 0;
  while (!q.empty()) {
    int th = q.front().first;
    int tw = q.front().second;
    q.pop();
    for (int i = (0); i < (4); ++i) {
      if (th + dy[i] < h && th + dy[i] >= 0 && tw + dx[i] < w &&
          tw + dx[i] >= 0 && vs[th + dy[i]][tw + dx[i]] == '.' &&
          !c[th + dy[i]][tw + dx[i]]) {
        d[th + dy[i]][tw + dx[i]] = d[th][tw] + 1;
        c[th + dy[i]][tw + dx[i]] = true;
        q.push(make_pair((th + dy[i]), (tw + dx[i])));
      }
    }
  }
  ma = -1;
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) {
      if (ma < d[i][j] && d[i][j] != 200000009) {
        sh = i;
        sw = j;
        ma = d[i][j];
      }
    }
  cout << ma << endl;
  return 0;
}
