#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int H, W;
  cin >> H >> W;
  string s[H + 2];
  s[0] = "";
  for (int i = 0; i < W + 2; i++) s[0] += "#";
  s[H + 1] = s[0];
  for (int i = 1; i <= H; i++) {
    cin >> s[i];
    s[i] = "#" + s[i] + "#";
  }
  int ans = 0;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#') continue;
      int d[H + 2][W + 2];
      for (int k = 0; k < H + 2; k++)
        for (int l = 0; l < W + 2; l++) d[k][l] = 100;
      queue<pair<long long, long long> > que;
      que.push(pair<long long, long long>(i, j));
      d[i][j] = 0;
      while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();
        int a = p.first, b = p.second;
        if (a == 0 || a == H + 1 || b == 0 || b == W + 1) continue;
        if (s[a + 1][b] == '.' && d[a + 1][b] > d[a][b] + 1) {
          d[a + 1][b] = d[a][b] + 1;
          que.push(pair<long long, long long>(a + 1, b));
        }
        if (s[a][b - 1] == '.' && d[a][b - 1] > d[a][b] + 1) {
          d[a][b - 1] = d[a][b] + 1;
          que.push(pair<long long, long long>(a, b - 1));
        }
        if (s[a][b + 1] == '.' && d[a][b + 1] > d[a][b] + 1) {
          d[a][b + 1] = d[a][b] + 1;
          que.push(pair<long long, long long>(a, b + 1));
        }
        if (s[a - 1][b] == '.' && d[a - 1][b] > d[a][b] + 1) {
          d[a - 1][b] = d[a][b] + 1;
          que.push(pair<long long, long long>(a - 1, b));
        }
        for (int i = 1; i <= H; i++)
          for (int j = 1; j <= W; j++) {
            if (d[i][j] == 100)
              continue;
            else
              ans = max(ans, d[i][j]);
          }
      }
    }
  cout << ans << endl;
}
