#include <bits/stdc++.h>
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, -1, 1};
int dis[405][405];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) cin >> v[i];
  for (int i = 0; i < 401; i++)
    for (int j = 0; j < 401; j++) dis[i][j] = INF;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < 4; k++) {
        if (v[i][j] == '#') continue;
        int next_x = j + dx[k], next_y = i + dy[k];
        if (next_x >= 0 && next_x < w && next_y >= 0 && next_y < h &&
            v[next_y][next_x] != '#') {
          dis[i * w + j][next_y * w + next_x] = 1;
        }
      }
    }
  }
  int n = 401;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dis[i][j] == INF) continue;
      ans = max(ans, dis[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
