#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932;
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<vector<int>> dist(1005, vector<int>(1005, INF));
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      int u = h * i + j;
      for (int k = 0; k < 4; ++k) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
        if (s[nx][ny] == '#') continue;
        int v = h * nx + ny;
        dist[u][v] = 1;
        dist[v][u] = 1;
      }
    }
  }
  int cnt = h * w;
  for (int i = 0; i <= cnt; ++i) {
    dist[i][i] = 0;
  }
  for (int k = 0; k < cnt; ++k) {
    for (int i = 0; i < cnt; ++i) {
      for (int j = 0; j < cnt; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < cnt; ++i) {
    for (int j = 0; j < cnt; ++j) {
      if (dist[i][j] == INF) continue;
      res = max(res, dist[i][j]);
    }
  }
  cout << res << endl;
}
