#include <bits/stdc++.h>
using namespace std;
long long N, M, K, X, H, W;
long long ans;
long long total;
long long S[25][25];
long long SS[25][25];
queue<pair<pair<long long, long long>, long long>> que;
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char a;
      cin >> a;
      if (a == '.') {
        S[i + 1][j + 1] = 1;
      }
    }
  }
  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++) {
          SS[k + 1][l + 1] = S[k + 1][l + 1];
        }
      }
      if (SS[i + 1][j + 1] == 1) {
        que.push(pair<pair<long long, long long>, long long>(
            pair<long long, long long>(i, j), 0));
        while (!que.empty() == 0) {
          pair<pair<long long, long long>, long long> c;
          c = que.front();
          que.pop();
          int k = c.first.first;
          int l = c.first.second;
          int z = c.second;
          SS[k + 1][l + 1] = 0;
          if (ans < z) {
            ans = z;
          }
          if (SS[k][l + 1] == 1) {
            que.push(pair<pair<long long, long long>, long long>(
                pair<long long, long long>(k - 1, l), z + 1));
          }
          if (SS[k + 1][l] == 1) {
            que.push(pair<pair<long long, long long>, long long>(
                pair<long long, long long>(k, l - 1), z + 1));
          }
          if (SS[k + 1][l + 2] == 1) {
            que.push(pair<pair<long long, long long>, long long>(
                pair<long long, long long>(k, l + 1), z + 1));
          }
          if (SS[k + 2][l + 1] == 1) {
            que.push(pair<pair<long long, long long>, long long>(
                pair<long long, long long>(k + 1, l), z + 1));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
