#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  int lastX = 0, lastY = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      cin >> S[i][j];
      if (S[i][j] == '.' && lastX == 0) {
        lastX = i;
        lastY = j;
      }
    }
  int llastX = -1, llastY = -1;
  int lllastX = -1, lllastY = -1;
  int max = 0;
  bool end = true;
  while (end) {
    max = 0;
    bool flag = true;
    vector<vector<int>> Ldist(H, vector<int>(W));
    while (flag) {
      vector<vector<int>> dist(H, vector<int>(W));
      dist = Ldist;
      dist[lastX][lastY] = 1;
      for (int i = 0; i < (int)(H); i++)
        for (int j = 0; j < (int)(W); j++) {
          int Ndist = dist[i][j];
          if (Ndist != 0) {
            int Ndist = dist[i][j];
            if (i != 0) {
              if (S[i - 1][j] == '.' && dist[i - 1][j] == 0)
                dist[i - 1][j] += Ndist + 1;
            }
            if (i != H - 1) {
              if (S[i + 1][j] == '.' && dist[i + 1][j] == 0)
                dist[i + 1][j] += Ndist + 1;
            }
            if (j != 0) {
              if (S[i][j - 1] == '.' && dist[i][j - 1] == 0)
                dist[i][j - 1] += Ndist + 1;
            }
            if (j != W - 1) {
              if (S[i][j + 1] == '.' && dist[i][j + 1] == 0)
                dist[i][j + 1] += Ndist + 1;
            }
          }
          if (max < Ndist) {
            max = Ndist;
            lastX = i;
            lastY = j;
          }
        }
      flag = Ldist != dist;
      Ldist = dist;
    }
    if (lllastX == lastX && lllastY == lastY) break;
    lllastX = llastX;
    lllastY = llastY;
    llastX = lastX;
    llastY = lastY;
  }
  llastX = lastX;
  llastY = lastY;
  cout << max - 1 << endl;
  return 0;
}
