#include <bits/stdc++.h>
using namespace std;
struct edge {
  using long long = long long int;
  int to;
  long long cost;
  edge(int t, long long c = 1) : to(t), cost(c) {}
};
void warshall_floyd(vector<vector<long long int>>& d) {
  long long int n = d.size();
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (d[i][k] == LLONG_MAX || d[k][j] == LLONG_MAX) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<long long>> d(h * w, vector<long long>(h * w, LLONG_MAX));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        if (i - 1 >= 0 && s[i - 1][j] == '.') {
          d[i * h + j][(i - 1) * h + j] = 1;
        }
        if (i + 1 < h && s[i + 1][j] == '.') {
          d[i * h + j][(i + 1) * h + j] = 1;
        }
        if (j - 1 >= 0 && s[i][j - 1] == '.') {
          d[i * h + j][i * h + j - 1] = 1;
        }
        if (j + 1 < w && s[i][j + 1] == '.') {
          d[i * h + j][i * h + j + 1] = 1;
        }
      }
    }
  }
  for (int i = 0; i < h * w; i++) {
    d[i][i] = 0;
  }
  warshall_floyd(d);
  long long ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (d[i][j] == LLONG_MAX) {
        continue;
      }
      ans = max(d[i][j], ans);
    }
  }
  cout << ans << endl;
}
