#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
string s;
long long h, w;
int now;
int dst[500];
char mp[500];
queue<int> que;
int mx = 0;
int pre = -1;
void func() {
  if (now < h * w && now >= 0) {
    if (mp[now] == '#') return;
    if (now % w == 0 && pre + 1 == now) return;
    if (pre % w == 0 && now + 1 == pre) return;
    if (dst[now] == -1) {
      dst[now] = dst[pre] + 1;
      que.push(now);
      mx = max(mx, dst[now]);
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h * w; i++) {
    cin >> mp[i];
  }
  for (int i = 0; i < h * w; i++) {
    if (mp[i] == '#') continue;
    for (int k = 0; k < h * w; k++) {
      dst[k] = -1;
    }
    dst[i] = 0;
    que.push(i);
    while (que.size()) {
      pre = que.front();
      que.pop();
      now = pre - w;
      func();
      now = pre - 1;
      func();
      now = pre + w;
      func();
      now = pre + 1;
      func();
    }
  }
  cout << mx << endl;
}
