#include <bits/stdc++.h>
using namespace std;
long long MM = 1000000000;
long long mod = MM + 7;
long long MMM = 9223372036854775807;
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return x / GCD(x, y) * y; }
long long fac(long long x) {
  if (x == 0) return 1;
  return x * fac(x - 1);
}
struct Corr {
  long long y;
  long long x;
  long long depth;
};
long long N, M;
long long y, x, depth;
vector<string> vec;
vector<long long> y_vec = {0, 0, -1, +1};
vector<long long> x_vec = {-1, +1, 0, 0};
long long bfs(long long &g_y, long long &g_x, queue<Corr> &q) {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    if (y == g_y && x == g_x) return depth;
    for (long long i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= N - 1 && 0 <= next.x && next.x <= M - 1 &&
          vec[next.y][next.x] == '.') {
        vec[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return 0;
}
int main() {
  long long h, w;
  long long ma = 0;
  cin >> h >> w;
  vec.resize(h + 2);
  for (long long i = 1; i < h + 1; ++i) {
    string S;
    cin >> S;
    S = '#' + S + '#';
    vec[i] = S;
  }
  string ss = "#";
  for (long long i = 0; i < w + 1; i++) {
    ss = ss + '#';
  }
  vec[0] = ss;
  vec[h + 1] = ss;
  for (long long s_y = 1; s_y <= h; s_y++) {
    for (long long s_x = 1; s_x <= w; s_x++) {
      for (long long g_y = 1; g_y <= h; g_y++) {
        for (long long g_x = 1; g_x <= w; g_x++) {
          if (s_y == g_y && s_x == g_x) continue;
          if (vec[s_y][s_x] == '#' || vec[g_y][g_x] == '#') continue;
          Corr start = {s_y, s_x, 0};
          queue<Corr> q;
          q.emplace(start);
          cout << bfs(g_y, g_x, q) << endl;
          ma = max(ma, bfs(g_y, g_x, q));
        }
      }
    }
  }
  cout << ma << endl;
  return 0;
}
