#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
struct Corr {
  long long x;
  long long y;
  long long depth;
};
long long w, h;
long long s_y, s_x, g_y, g_x;
long long x, y, depth;
vector<string> vec;
vector<string> orig;
queue<Corr> q;
vector<long long> x_vec = {0, 0, -1, +1};
vector<long long> y_vec = {-1, +1, 0, 0};
long long bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    x = now.x, y = now.y, depth = now.depth;
    if (x == g_x && y == g_y) {
      return depth;
    }
    for (long long i = 0; i < 4; ++i) {
      Corr next = {x + x_vec[i], y + y_vec[i], depth + 1};
      if (0 <= next.y && next.y <= w - 1 && 0 <= next.x && next.x <= h - 1 &&
          vec[next.x][next.y] == '.') {
        vec[next.x][next.y] = 'x';
        q.push(next);
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  vec.resize(h);
  orig.resize(h);
  long long ans = 0;
  for (long long i = 0; i < h; ++i) {
    cin >> vec[i];
    cin >> orig[i];
  }
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      Corr start = {i, j, 0};
      q.push(start);
      ans = max(ans, bfs());
      for (int k = 0; k < (int)(h); k++) {
        vec[k] = orig[k];
      }
    }
  }
  cout << ans << endl;
}
