#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9 + 10;
int H, W;
vector<string> S(25);
int res = 0;
vector<int> di = {1, 0, -1, 0};
vector<int> dj = {0, 1, 0, -1};
void bfs(int si, int sj, int ti, int tj) {
  int dist[25][25];
  for (int i = 0; i < (25); ++i)
    for (int j = 0; j < (25); ++j) dist[i][j] = -1;
  queue<P> q;
  q.push(P(si, sj));
  dist[si][sj] = 0;
  while (!q.empty()) {
    P cur = q.front();
    q.pop();
    int ci = cur.first, cj = cur.second;
    if (ci == ti && cj == tj) {
      res = max(res, dist[ci][cj]);
      return;
    }
    for (int k = 0; k < (4); ++k) {
      int ni = ci + di[k], nj = cj + dj[k];
      if (ni < 0 || ni > H || nj < 0 || nj > W) continue;
      if (S[ni][nj] == '.' && dist[ni][nj] == -1) {
        dist[ni][nj] = dist[ci][cj] + 1;
        q.push(P(ni, nj));
      }
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) cin >> S[i];
  for (int si = 0; si < (H); ++si)
    for (int sj = 0; sj < (W); ++sj)
      for (int ti = 0; ti < (H); ++ti)
        for (int tj = 0; tj < (W); ++tj) {
          bfs(si, sj, ti, tj);
        }
  cout << res << endl;
}
