#include <bits/stdc++.h>
using namespace std;
template <typename T>
T changeMax(T& a, T b) {
  if (a < b) a = b;
  return 0;
}
int h, w;
char s[25][25];
int bfs(int i, int j, int k, int l) {
  int s_x, s_y, g_x, g_y;
  s_y = i;
  s_x = j;
  g_y = k;
  g_x = l;
  int d[25][25], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  memset(d, -1, sizeof(d));
  queue<pair<int, int> > q;
  pair<int, int> a(s_x, s_y);
  q.push(a);
  d[s_y][s_x] = 0;
  while (q.size()) {
    pair<int, int> t = q.front();
    q.pop();
    if (t.first == g_x && t.second == g_y) {
      return d[g_y][g_x];
    }
    for (int i = 0; i < 4; i++) {
      int l = t.first + dx[i], r = t.second + dy[i];
      if (0 <= l && l < w && 0 <= r && r < h && s[r][l] != '#' &&
          d[r][l] == -1) {
        d[r][l] = d[t.second][t.first] + 1;
        pair<int, int> k(l, r);
        q.push(k);
      }
    }
  }
  return -1;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (i == k && j == l) continue;
          ans = max(ans, bfs(i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
  system("pause");
  return 0;
}
