#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, -1, 0, 1};
long long h, w;
vector<string> v(30);
long long call(long long i, long long j) {
  queue<long long> q;
  vector<long long> vis(10000);
  vis[i * w + j] = 0;
  long long ans = 0;
  q.push(i * w + j);
  while (q.size()) {
    long long x = q.front();
    q.pop();
    long long i = x / w, j = x % w;
    for (long long a = 0; a < 4; a++) {
      long long x = i + dx[a];
      long long y = j + dy[a];
      if (x < h && x >= 0 && y < w && y >= 0 && v[x][y] == '.' &&
          vis[x * w + y] == 0) {
        vis[x * w + y] = vis[i * w + j] + 1;
        q.push(x * w + y);
      }
    }
  }
  return *(max_element(vis.begin(), vis.end()));
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    cin >> v[i];
  }
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (v[i][j] == '.') {
        long long val = call(i, j);
        ans = max(ans, val);
      }
    }
  }
  cout << ans << "\n";
}
