#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) cin >> S[i];
  vector<vector<long long int>> g(H * W, vector<long long int>(H * W, INF));
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++)
        for (int s = 0; s < W; s++) {
          if (abs(i - k) + abs(j - s) == 1 && S[i][j] != '#' &&
              S[k][s] != '#') {
            g[i * W + j][k * W + s] = 1;
            g[k * W + s][i * W + j] = 1;
          }
        }
    }
  for (int k = 0; k < H * W; k++)
    for (int i = 0; i < H * W; i++)
      for (int j = 0; j < H * W; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
  long long int ans = 0;
  for (int i = 0; i < H * W; i++)
    for (int j = 0; j < H * W; j++) {
      if (g[i][j] >= INF) continue;
      ans = max(g[i][j], ans);
    }
  cout << ans << endl;
}
