#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
string S[30];
int d[30][30][30][30];
struct P {
  int x, y;
};
int tox[] = {0, 1, 0, -1};
int toy[] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#') {
        queue<P> Q;
        Q.push({i, j});
        while (!Q.empty()) {
          P p = Q.front();
          Q.pop();
          for (int k = 0; k < 4; k++) {
            if (p.x + tox[k] < W && p.x + tox[k] >= 0 && p.y + toy[k] < H &&
                p.y + toy[k] >= 0 && d[i][j][p.y + toy[k]][p.x + tox[k]] == 0 &&
                S[p.y + toy[k]][p.x + tox[k]] == '.') {
              Q.push({p.x + tox[k], p.y + toy[k]});
              d[i][j][p.y + toy[k]][p.x + tox[k]] = d[i][j][p.y][p.x] + 1;
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          ans = max(ans, d[i][j][k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
