#include <bits/stdc++.h>
using namespace std;
bool ngoin(vector<vector<bool> > bo, vector<int> now) {
  return 0 <= now[0] && now[0] < bo.size() && 0 <= now[1] &&
         now[1] < bo[0].size();
}
long minido(vector<vector<bool> > bo, int si, int sj, int ei, int ej) {
  vector<vector<bool> > tb(bo.size(), vector<bool>(bo[0].size(), false));
  queue<vector<int> > q;
  q.push({si, sj, 0});
  while (!q.empty()) {
    vector<int> now = q.front();
    q.pop();
    if (now[0] == ei && now[1] == ej) {
      return now[2];
    }
    if (tb[now[0]][now[1]]) continue;
    if (ngoin(bo, {now[0] - 1, now[1]})) {
      if (bo[now[0] - 1][now[1]]) q.push({now[0] - 1, now[1], now[2] + 1});
    }
    if (ngoin(bo, {now[0], now[1] + 1})) {
      if (bo[now[0]][now[1] + 1]) q.push({now[0], now[1] + 1, now[2] + 1});
    }
    if (ngoin(bo, {now[0] + 1, now[1]})) {
      if (bo[now[0] + 1][now[1]]) q.push({now[0] + 1, now[1], now[2] + 1});
    }
    if (ngoin(bo, {now[0], now[1] - 1})) {
      if (bo[now[0]][now[1] - 1]) q.push({now[0], now[1] - 1, now[2] + 1});
    }
  }
}
int main(void) {
  int h, w;
  cin >> h;
  cin >> w;
  vector<vector<bool> > board(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      board[i][j] = s[j] == '.' ? true : false;
    }
  }
  int ans = 0;
  for (int si = 0; si < h; si++) {
    for (int sj = 0; sj < w; sj++) {
      for (int ei = 0; ei < h; ei++) {
        for (int ej = 0; ej < w; ej++) {
          if ((!board[si][sj]) || (!board[ei][ej])) continue;
          int ngo = minido(board, si, sj, ei, ej);
          if (ans < ngo) {
            ans = ngo;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
