#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e15;
bool d[22][22];
long long mp[22][22];
vector<long long> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
  long long H, W;
  cin >> H >> W;
  for (int i = 1; i < H + 1; i++) {
    string S;
    cin >> S;
    for (int j = 1; j < W + 1; j++)
      if (S.at(j - 1) == '.') d[i][j] = true;
  }
  long long ans = 0;
  for (int p = 1; p < H + 1; p++)
    for (int q = 1; q < W + 1; q++) {
      long long Start = p * 23 + q;
      for (int i = 0; i < 22; i++)
        for (int j = 0; j < 22; j++) mp[i][j] = -1;
      long long MAX = 0;
      mp[p][q] = 0;
      queue<long long> Q;
      Q.push(Start);
      while (!Q.empty()) {
        long long X = Q.front();
        Q.pop();
        long long h = X / 23, w = X % 23;
        for (int i = 0; i < 4; i++) {
          long long hh = h + dx.at(i), ww = w + dy.at(i);
          if (d[hh][ww]) {
            if (mp[hh][ww] == -1) {
              mp[hh][ww] = mp[h][w] + 1;
              Q.push(hh * 23 + ww);
              MAX = mp[hh][ww];
            }
          }
        }
      }
      ans = max(MAX, ans);
    }
  cout << ans << endl;
}
