#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> v;
int d[30][30];
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    v.push_back(S);
  }
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      int ix = i % W, iy = i / W;
      int jx = j % W, jy = j / W;
      if (abs(ix - jx) + abs(iy - jy) == 1 && v[iy][ix] == '.' &&
          v[jy][jx] == '.') {
        d[i][j] = d[j][i] = 1;
      } else if (i == j) {
        d[i][j] = d[j][i] = 0;
      } else {
        d[i][j] = d[j][i] = INT_MAX / 3;
      }
    }
  }
  for (int k = 0; k < H * W; k++) {
    for (int i = 0; i < H * W; i++) {
      for (int j = 0; j < H * W; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (v[i][j] == '.') {
        for (int ii = 0; ii < H; ii++) {
          for (int jj = 0; jj < W; jj++) {
            if (v[ii][jj] == '.') {
              ans = max(ans, d[ii * W + jj][i * W + j]);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
