#include <bits/stdc++.h>
using namespace std;
void Ans(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
const long long int INF = 1001001001;
const long long int mod = 10000000007;
int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) cin >> s[i][j];
  vector<int> dx, dy;
  int ans = 0;
  dx = {1, 0, -1, 0};
  dy = {0, 1, 0, -1};
  queue<pair<int, int> > q;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      int dist[h][w];
      for (int l = 0; l < (int)(h); l++)
        for (int k = 0; k < (int)(w); k++) dist[l][k] = -1;
      q.push(pair<int, int>(i, j));
      dist[i][j] = 0;
      while (!(q.empty())) {
        pair<int, int> now = q.front();
        q.pop();
        for (int l = 0; l < (int)(4); l++) {
          int nx = now.first + dx[l];
          int ny = now.second + dy[l];
          if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
          if (s[nx][ny] == '.' && dist[nx][ny] == -1) {
            q.push(pair<int, int>(nx, ny));
            dist[nx][ny] = dist[now.first][now.second] + 1;
            ans = max(dist[nx][ny], ans);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
