#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int h, w;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool isInside(int y, int x) {
  if (y < 0 || y >= h) return false;
  if (x < 0 || x >= w) return false;
  return true;
}
int calc(int sh, int sw, vector<string> s) {
  vector<vector<int>> d(h, vector<int>(w, INF));
  d[sh][sw] = 0;
  queue<pair<int, int>> q;
  q.push({sh, sw});
  int res = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (!isInside(ny, nx)) {
        continue;
      }
      if (s[ny][nx] == '#') {
        continue;
      }
      if (d[ny][nx] > d[p.first][p.second] + 1) {
        d[ny][nx] = d[p.first][p.second] + 1;
        res = max(res, d[ny][nx]);
        q.push({ny, nx});
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, calc(i, j, s));
    }
  }
  cout << ans << endl;
  return 0;
}
