#include <bits/stdc++.h>
using namespace std;
long long graph[500][500];
char mas[500][500];
int h, w;
int zip(int y, int x) { return y * w + x; }
bool isOK(int y, int x) {
  return 0 <= y && y < h && 0 <= x && x < w && mas[y][x] == '.';
}
int main() {
  cin >> h >> w;
  int n = h * w;
  for (int i = 0; i < h; i++) {
    cin >> mas[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          graph[zip(i, j)][zip(k, l)] = INT_MAX;
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (mas[i][j] != '#') graph[zip(i, j)][zip(i, j)] = 0;
      if (isOK(i, j + 1)) graph[zip(i, j)][zip(i, j + 1)] = 1;
      if (isOK(i, j - 1)) graph[zip(i, j)][zip(i, j - 1)] = 1;
      if (isOK(i + 1, j)) graph[zip(i, j)][zip(i + 1, j)] = 1;
      if (isOK(i - 1, j)) graph[zip(i, j)][zip(i - 1, j)] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          int tmp = graph[zip(i, j)][zip(k, l)];
          if (tmp != INT_MAX) {
            ans = max(ans, tmp);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
