#include <bits/stdc++.h>
using namespace std;
struct Corr {
  long long y;
  long long x;
  long long depth;
};
long long N, M;
long long s_y, s_x, g_y, g_x;
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(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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  vector<string> meiro;
  for (int j = 0; j < N; j++) {
    string s;
    cin >> s;
    meiro.push_back(s);
  }
  long long ans = 0;
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < M; i++) {
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < M; l++) {
          queue<Corr> q;
          vec = meiro;
          s_y = j, s_x = i;
          g_y = k, g_x = l;
          Corr start = {s_y, s_x, 0};
          q.emplace(start);
          long long ret = bfs(q);
          if (ret > ans) ans = ret;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
