#include <bits/stdc++.h>
using namespace std;
int h, w;
bool masu[20 * 20] = {};
int total;
int go(int now, int dir) {
  int next;
  switch (dir) {
    case (0):
      next = now - w;
      break;
    case (1):
      if (now % w == w - 1)
        next = -1;
      else
        next = now + 1;
      break;
    case (2):
      next = now + w;
      break;
    case (3):
      if (now % w == 0)
        next = -1;
      else
        next = now - 1;
      break;
  }
  if (next >= total) next = -1;
  if (next >= 0 && !masu[next]) next = -1;
  return next;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (h); i++) {
    string s;
    cin >> s;
    for (int j = 0; j < (w); j++) masu[i * w + j] = (s[j] == '.');
  }
  total = h * w;
  int ans = 0;
  for (int i = 0; i < (total); i++) {
    if (!masu[i]) continue;
    queue<pair<int, int>> q;
    q.push(pair<int, int>(i, 0));
    vector<int> root(total, 0);
    while (!q.empty()) {
      int now = q.front().first;
      int count = q.front().second;
      q.pop();
      root[now] = 1;
      for (int j = 0; j < (4); j++) {
        int next;
        if ((next = go(now, j)) >= 0 && root[next] == 0) {
          q.push(pair<int, int>(next, count + 1));
        }
      }
      ans = max(ans, count);
    }
  }
  cout << ans << endl;
  return 0;
}
