#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
ll h, w;
vector<vector<char>> v(20, vector<char>(20, '#'));
vector<ll> x = {1, 0, -1, 0};
vector<ll> y = {0, 1, 0, -1};
vector<vector<ll>> d(20, vector<ll>(20, INF));
void dfs(ll sx, ll sy, ll gx, ll gy) {
  if (sx == gx && sy == gy) return;
  for (int i = 0; i < (ll)(4); i++) {
    ll nx = sx + x.at(i), ny = sy + y.at(i);
    if (0 <= nx && nx < 20 && 0 <= ny && ny < 20) {
      if (v.at(nx).at(ny) == '.') {
        if (d.at(sx).at(sy) + 1 < d.at(nx).at(ny)) {
          d.at(nx).at(ny) = d.at(sx).at(sy) + 1;
          dfs(nx, ny, gx, gy);
        }
      }
    }
  }
  return;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (ll)(h); i++) {
    for (int j = 0; j < (ll)(w); j++) {
      cin >> v.at(i).at(j);
    }
  }
  ll res = 0;
  vector<vector<ll>> tmp(20, vector<ll>(20, INF));
  for (int i = 0; i < (ll)(h); i++) {
    for (int j = 0; j < (ll)(w); j++) {
      if (v.at(i).at(j) == '.') {
        for (int k = 0; k < (ll)(h); k++) {
          for (int l = 0; l < (ll)(w); l++) {
            if (v.at(k).at(l) == '.') {
              if (i != k || j != l) {
                d = tmp;
                d.at(i).at(j) = 0;
                dfs(i, j, k, l);
                if (d.at(k).at(l) != INF) res = max(res, d.at(k).at(l));
              }
            }
          }
        }
      }
    }
  }
  cout << res << endl;
}
