#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1ll << 60;
long long pow(long long x, long long y) {
  long long ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}
long long inverse(long long x) { return pow(x, mod - 2); }
int main() {
  long long H, W;
  cin >> H >> W;
  vector<vector<long long> > m(H, vector<long long>(W));
  for (int i = (0); i < (H); i++) {
    string s;
    cin >> s;
    for (int j = (0); j < (W); j++) {
      if (s[j] == '.') {
        m[i][j] = 1;
      }
    }
  }
  auto f = [&](long long x, long long y) {
    vector<vector<long long> > dist(H, vector<long long>(W, INF));
    queue<pair<long long, long long> > q;
    q.emplace(x, y);
    dist[x][y] = 0;
    while (q.size()) {
      pair<long long, long long> fr = q.front();
      q.pop();
      vector<long long> dx{-1, 0, 1, 0};
      vector<long long> dy{0, 1, 0, -1};
      for (int i = (0); i < (4); i++) {
        long long x = fr.first + dx[i];
        long long y = fr.second + dy[i];
        if (x < 0 || x >= H || y < 0 || y >= W) continue;
        if (m[x][y] && dist[x][y] == INF) {
          dist[x][y] = dist[fr.first][fr.second] + 1;
          q.emplace(x, y);
        }
      }
    }
    long long ans = 0;
    for (int i = (0); i < (H); i++) {
      for (int j = (0); j < (W); j++) {
        if (dist[i][j] != INF) ans = max(ans, dist[i][j]);
      }
    }
    return ans;
  };
  long long ans = 0;
  for (int i = (0); i < (H); i++) {
    for (int j = (0); j < (W); j++) {
      ans = max(ans, f(i, j));
    }
  }
  cout << ans << endl;
}
