#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v;
  vector<string> dist;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    dist.push_back(s);
  }
  int mat[n * m][n * m];
  for (int i = 0; i < n * m; i++)
    for (int j = 0; j < m * n; j++) mat[i][j] = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - 1 > 0 && dist[i - 1][j] == '.' && dist[i][j] == '.') {
        mat[m * (i - 1) + j][m * i + j] = 1;
        mat[m * i + j][m * (i - 1) + j] = 1;
      }
      if (i + 1 < n && dist[i + 1][j] == '.' && dist[i][j] == '.') {
        mat[m * (i + 1) + j][m * i + j] = 1;
        mat[m * i + j][m * (i + 1) + j] = 1;
      }
      if (j - 1 > 0 && dist[i][j - 1] == '.' && dist[i][j] == '.') {
        mat[m * i + j][m * i + (j - 1)] = 1;
        mat[m * i + (j - 1)][m * i + j] = 1;
      }
      if (j + 1 < m && dist[i][j + 1] == '.' && dist[i][j] == '.') {
        mat[m * i + j][m * i + (j + 1)] = 1;
        mat[m * i + (j + 1)][m * i + j] = 1;
      }
    }
  }
  for (int k = 0; k < n * m; k++) {
    for (int i = 0; i < n * m; i++) {
      for (int j = 0; j < n * m; j++) {
        if (mat[i][k] != INT_MAX && mat[k][j] != INT_MAX &&
            (mat[i][k] + mat[k][j] < mat[i][j]))
          mat[i][j] = mat[i][k] + mat[k][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n * m; i++)
    for (int j = 0; j < m * n; j++)
      mat[i][j] != INT_MAX ? ans = max(ans, mat[i][j]) : ans = max(ans, ans);
  cout << ans;
  return 0;
}
