#include <bits/stdc++.h>
using namespace std;
int oo = 0x3f3f3f3f;
int dist[400][400];
int pre[400][400];
void floyd(int n) {
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (n); j++) pre[i][j] = i;
  for (int k = (0); k < (n); k++)
    for (int i = (0); i < (n); i++)
      for (int j = (0); j < (n); j++)
        if (dist[i][k] < oo && dist[k][j] < oo &&
            dist[i][k] + dist[k][j] < dist[i][j]) {
          dist[i][j] = max(dist[i][k] + dist[k][j], -oo);
          pre[i][j] = (pre[k][j] != j ? pre[k][j] : pre[i][k]);
        }
}
int main() {
  vector<vector<int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < 400; i++) {
    for (int j = 0; j < 400; j++) {
      dist[i][j] = oo;
    }
  }
  vector<vector<bool>> s = vector<vector<bool>>(h, vector<bool>(w, false));
  string si;
  vector<vector<int>> node_num = vector<vector<int>>(h, vector<int>(w, -1));
  int node_count = 0;
  for (int i = 0; i < h; i++) {
    cin >> si;
    for (int j = 0; j < w; j++) {
      if (si[j] == '.') {
        node_num[i][j] = node_count;
        node_count++;
        s[i][j] = true;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!s[i][j]) continue;
      for (int k = 0; k < 4; k++) {
        vector<int> dir = dirs[k];
        if (i + dir[0] >= 0 && i + dir[0] < h && j + dir[1] >= 0 &&
            j + dir[1] < w) {
          if (s[i + dir[0]][j + dir[1]]) {
            dist[node_num[i][j]][node_num[i + dir[0]][j + dir[1]]] = 1;
          }
        }
      }
    }
  }
  floyd(node_count);
  int max_dist = -1;
  for (int i = (0); i < (400); i++)
    for (int j = (0); j < (400); j++) {
      if (dist[i][j] != oo) max_dist = max(max_dist, dist[i][j]);
    }
  cout << max_dist << endl;
  return 0;
}
