#include <bits/stdc++.h>
using namespace std;
long long xx[4] = {-1, 0, 1, 0};
long long yy[4] = {0, 1, 0, -1};
bool isValid(long long i, long long j, vector<vector<bool>> &visited,
             vector<string> &G) {
  if (i >= 0 && i < visited.size() && j >= 0 && j < visited[0].size() &&
      G[i][j] == '.' && !visited[i][j]) {
    return true;
  } else {
    return false;
  }
}
int main() {
  long long h, w;
  cin >> h >> w;
  vector<string> G(h);
  for (long long i = 0; i < h; i++) {
    cin >> G[i];
  }
  long long res = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      vector<vector<bool>> visited(h, vector<bool>(w, false));
      visited[i][j] = true;
      queue<pair<pair<long long, long long>, long long>> q;
      q.push({{i, j}, 0});
      while (!q.empty()) {
        auto t = q.front();
        long long x = t.first.first;
        long long y = t.first.second;
        q.pop();
        res = max(res, t.second);
        for (int k = 0; k < 4; k++) {
          if (isValid(x + xx[k], y + yy[k], visited, G)) {
            visited[x + xx[k]][y + yy[k]] = true;
            q.push({{x + xx[k], y + yy[k]}, t.second + (long long)1});
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
