#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 62;
void floydWarshall(vector<vector<long long>>& m) {
  int n = ((int)(m).size());
  for (int i = (0); i < (n); ++i)
    m[i][i] = ((m[i][i]) < (0LL) ? (m[i][i]) : (0LL));
  for (int k = (0); k < (n); ++k)
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j)
        if (m[i][k] != inf && m[k][j] != inf) {
          auto newDist =
              ((m[i][k] + m[k][j]) > (-inf) ? (m[i][k] + m[k][j]) : (-inf));
          m[i][j] = ((m[i][j]) < (newDist) ? (m[i][j]) : (newDist));
        }
  for (int k = (0); k < (n); ++k)
    if (m[k][k] < 0)
      for (int i = (0); i < (n); ++i)
        for (int j = (0); j < (n); ++j)
          if (m[i][k] != inf && m[k][j] != inf) m[i][j] = -inf;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> grid(h, vector<char>(w));
  vector<vector<long long>> mat(401, vector<long long>(401, inf));
  for (int i = (0); i < (h); ++i)
    for (int j = (0); j < (w); ++j) {
      cin >> grid[i][j];
    }
  for (int i = (0); i < (h); ++i) {
    for (int j = (0); j < (w); ++j) {
      for (int di = (-1); di < (2); ++di)
        for (int dj = (-1); dj < (2); ++dj) {
          if (abs(di) + abs(dj) != 1) continue;
          int ni = i + di, nj = j + dj;
          if (not(ni >= 0 and ni < h and nj >= 0 and nj < w)) continue;
          if (grid[ni][nj] != '.') continue;
          mat[(i * w + j)][(ni * w + nj)] = 1;
        }
    }
  }
  floydWarshall(mat);
  long long ans = 0;
  for (int i = (0); i < (w * h); ++i) {
    for (int j = (0); j < (w * h); ++j) {
      if (mat[i][j] == inf) continue;
      ans = ((ans) > (mat[i][j]) ? (ans) : (mat[i][j]));
    }
  }
  cout << ans << endl;
}
