#include <bits/stdc++.h>
using namespace std;
int H, W;
string s[20];
int dir[5] = {0, 1, 0, -1, 0};
vector<vector<int> > calc(int sx, int sy) {
  vector<vector<int> > d(H, vector<int>(W, 1e9));
  d[sx][sy] = 0;
  queue<pair<int, int> > P;
  P.push(make_pair(sx, sy));
  while (!P.empty()) {
    int x = P.front().first, y = P.front().second;
    P.pop();
    for (int r = 0; r < 4; r++) {
      int tx = x + dir[r], ty = y + dir[r + 1];
      if (tx < 0 || ty < 0 || tx >= H || ty >= W || s[tx][ty] == '#' ||
          d[tx][ty] < d[x][y] + 1)
        continue;
      d[tx][ty] = d[x][y] + 1;
      P.push(make_pair(tx, ty));
    }
  }
  return d;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      vector<vector<int> > d = calc(i, j);
      for (int I = 0; I < H; I++)
        for (int J = 0; J < W; J++) {
          if (d[I][J] < 1e9) ans = max(ans, d[I][J]);
        }
    }
  cout << ans << endl;
}
