#include <bits/stdc++.h>
using namespace std;
const long long zero = 0;
const long long INF = 3000000000000000000;
const int inINF = 1000000000;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> G(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> G[i][j];
    }
  }
  queue<pair<int, int>> q;
  vector<vector<int>> A(H, vector<int>(W));
  vector<int> x(4);
  vector<int> y(4);
  x[0] = 1;
  x[1] = -1;
  x[2] = 0;
  x[3] = 0;
  y[0] = 0;
  y[1] = 0;
  y[2] = 1;
  y[3] = -1;
  int h, w, tmp, ans;
  ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        fill((A[k]).begin(), (A[k]).end(), inINF);
      }
      q.push(make_pair(i, j));
      A[i][j] = 0;
      while (!q.empty()) {
        h = q.front().first;
        w = q.front().second;
        q.pop();
        for (int k = 0; k < 4; k++) {
          if (h + x[k] < H && h + x[k] >= 0 && w + y[k] < W && w + y[k] >= 0) {
            if (A[h + x[k]][w + y[k]] < A[h][w] + 1) continue;
            if (G[h + x[k]][w + y[k]] == '.') {
              A[h + x[k]][w + y[k]] = A[h][w] + 1;
              q.push(make_pair(h + x[k], w + y[k]));
            }
          }
        }
      }
      tmp = 0;
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if (A[k][l] != inINF) {
            tmp = max(tmp, A[k][l]);
          }
        }
      }
      ans = max(ans, tmp);
    }
  }
  printf("%d\n", ans);
}
