#include <bits/stdc++.h>
using namespace std;
int n, m;
char arr[30][30];
int dist[404][404], ans;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &arr[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '#') continue;
      if (i && arr[i - 1][j] == '.')
        dist[i + n * j][i - 1 + n * j] = 1, dist[i - 1 + n * j][i + n * j] = 1;
      if (j && arr[i][j - 1] == '.')
        dist[i + n * j][i + n * (j - 1)] = 1,
                                     dist[i + n * (j - 1)][i + n * j] = 1;
      if (i + 1 < n && arr[i + 1][j] == '.')
        dist[i + n * j][i + 1 + n * j] = 1, dist[i + 1 + n * j][i + n * j] = 1;
      if (j + 1 < m && arr[i][j + 1] == '.')
        dist[i + n * j][i + n * (j + 1)] = 1,
                                     dist[i + n * (j + 1)][i + n * j] = 1;
    }
  }
  for (int i = 0; i < 400; i++) {
    for (int j = 0; j < 400; j++)
      if (dist[i][j] == 0) {
        dist[i][j] = 1000000007;
      }
  }
  for (int k = 0; k < 400; k++) {
    for (int i = 0; i < 400; i++) {
      for (int j = 0; j < 400; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
  }
  for (int i = 0; i < 400; i++) {
    for (int j = 0; j < 400; j++)
      if (dist[i][j] != 1000000007 && dist[i][j] > ans) {
        ans = dist[i][j];
      }
  }
  printf("%d", ans);
}
