#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char maz[30][30];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maz[i][j];
    }
  }
  queue<int> qi;
  queue<int> qj;
  int ans[400][400];
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      ans[i][j] = -1;
    }
  }
  for (int i = 0; i < H * W; i++) ans[i][i] = 0;
  bool vis[30][30];
  int x[] = {0, 1, 0, -1};
  int y[] = {1, 0, -1, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (maz[i][j] == '#') continue;
      qi.push(i);
      qj.push(j);
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          vis[k][l] = false;
        }
      }
      while (!qi.empty()) {
        int k = qi.front();
        int l = qj.front();
        qi.pop();
        qj.pop();
        vis[k][l] = true;
        for (int p = 0; p < 4; p++) {
          int vi = k + x[p];
          int vj = l + y[p];
          if (vi < 0 || vi >= H) continue;
          if (vj < 0 || vj >= W) continue;
          if (maz[vi][vj] == '#') continue;
          if (vis[vi][vj]) continue;
          ans[vi * W + vj][i * W + j] = ans[k * W + l][i * W + j] + 1;
          qi.push(vi);
          qj.push(vj);
        }
      }
    }
  }
  int kj = 0;
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      kj = max(kj, ans[i][j]);
    }
  }
  cout << kj << endl;
}
