#include <bits/stdc++.h>
using namespace std;
string s[31];
long long n, m;
long long dp[31][31];
long long v[31][31];
map<pair<long long, long long>, long long> d;
long long find(long long x, long long y, long long e, long long f) {
  queue<pair<long long, long long>> q;
  q.push(make_pair(x, y));
  d[make_pair(x, y)] = 0;
  while (q.size() != 0) {
    pair<long long, long long> p = q.front();
    long long i = p.first;
    long long j = p.second;
    q.pop();
    v[i][j] = 1;
    if (i == e && j == f) {
      return d[make_pair(i, j)];
    }
    if (i + 1 < n && s[i + 1][j] == '.' && v[i + 1][j] == 0) {
      q.push(make_pair(i + 1, j));
      d[make_pair(i + 1, j)] = d[make_pair(i, j)] + 1;
    }
    if (j + 1 < m && s[i][j + 1] == '.' && v[i][j + 1] == 0) {
      q.push(make_pair(i, j + 1));
      d[make_pair(i, j + 1)] = d[make_pair(i, j)] + 1;
    }
    if (i - 1 > -1 && s[i - 1][j] == '.' && v[i - 1][j] == 0) {
      q.push(make_pair(i - 1, j));
      d[make_pair(i - 1, j)] = d[make_pair(i, j)] + 1;
    }
    if (j - 1 > -1 && s[i][j - 1] == '.' && v[i][j - 1] == 0) {
      q.push(make_pair(i, j - 1));
      d[make_pair(i, j - 1)] = d[make_pair(i, j)] + 1;
    }
  }
  return -1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  long long i, j, e, f;
  for (i = 0; i < n; i++) cin >> s[i];
  long long ans = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        for (e = 0; e < n; e++) {
          for (f = 0; f < m; f++) {
            cerr << "e"
                 << ": " << e << " | "
                 << "f"
                 << ": " << f << " | "
                 << "i"
                 << ": " << i << " | "
                 << "j"
                 << ": " << j << endl;
            if (s[e][f] == '.') {
              long long x = find(i, j, e, f);
              memset(v, 0, sizeof(v));
              ans = max(ans, x);
            }
          }
        }
      }
    }
  }
  cout << ans << '\n';
}
