#include <bits/stdc++.h>
using namespace std;
long long bfs(long long sx, long long sy, vector<vector<char>>& mat) {
  long long n = mat.size();
  long long m = mat[0].size();
  queue<long long> qx;
  queue<long long> qy;
  queue<long long> lv;
  qx.push(sx);
  qy.push(sy);
  lv.push(0);
  long long xi[4] = {1, -1, 0, 0};
  long long yi[4] = {0, 0, 1, -1};
  long long ans = 0;
  bool vis[n][m];
  memset(vis, 0, sizeof(vis));
  while (qx.size() != 0) {
    long long x = qx.front();
    long long y = qy.front();
    long long l = lv.front();
    qx.pop();
    qy.pop();
    lv.pop();
    ans = max(ans, l);
    for (long long i = 0; i < 4; i++) {
      long long xn = x + xi[i];
      long long yn = y + yi[i];
      if (xn >= 0 && xn < n && yn >= 0 && yn < m && vis[xn][yn] == false &&
          mat[xn][yn] == '.') {
        vis[xn][yn] = true;
        qx.push(xn);
        qy.push(yn);
        lv.push(l + 1);
      }
    }
  }
  return ans;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<char>> mat(n, vector<char>(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cin >> mat[i][j];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (mat[i][j] == '.') ans = max(ans, bfs(i, j, mat));
    }
  }
  cout << ans;
}
