#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> find_farest(int x, int y, int map[][22]) {
  int dist[22][22];
  for (int i = 0; i < (22); ++i) {
    for (int j = 0; j < (22); ++j) {
      dist[i][j] = -1;
    }
  }
  dist[x][y] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int s = p.first, t = p.second;
    if (map[s - 1][t] &&
        (dist[s - 1][t] == -1 || dist[s - 1][t] > dist[s][t] + 1)) {
      dist[s - 1][t] = dist[s][t] + 1;
      q.push(make_pair(s - 1, t));
    }
    if (map[s + 1][t] &&
        (dist[s + 1][t] == -1 || dist[s + 1][t] > dist[s][t] + 1)) {
      dist[s + 1][t] = dist[s][t] + 1;
      q.push(make_pair(s + 1, t));
    }
    if (map[s][t - 1] &&
        (dist[s][t - 1] == -1 || dist[s][t - 1] > dist[s][t] + 1)) {
      dist[s][t - 1] = dist[s][t] + 1;
      q.push(make_pair(s, t - 1));
    }
    if (map[s][t + 1] &&
        (dist[s][t + 1] == -1 || dist[s][t + 1] > dist[s][t] + 1)) {
      dist[s][t + 1] = dist[s][t] + 1;
      q.push(make_pair(s, t + 1));
    }
  }
  int maxd = -1, mx, my;
  for (int i = 0; i < (22); ++i) {
    for (int j = 0; j < (22); ++j) {
      if (dist[i][j] > maxd) {
        maxd = dist[i][j];
        mx = i;
        my = j;
      }
    }
  }
  return make_pair(make_pair(mx, my), maxd);
}
int main() {
  int H, W, map[22][22] = {};
  cin >> H >> W;
  int sx, sy;
  for (int i = 0; i < (H); ++i) {
    string S;
    cin >> S;
    for (int j = 0; j < (W); ++j) {
      if (S[j] == '.') {
        map[i + 1][j + 1] = true;
        sx = i + 1;
        sy = j + 1;
      }
    }
  }
  pair<pair<int, int>, int> f1 = find_farest(sx, sy, map);
  pair<pair<int, int>, int> f2 =
      find_farest(f1.first.first, f1.first.second, map);
  cout << f2.second << endl;
}
