#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long long day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long mod;
long long h, w;
long long mx = -1;
vector<long long> adj[1000];
bool vis[20][20];
long long level[20][20];
string s[20];
void dfs(long long x, long long y) {
  queue<pair<long long, long long>> q;
  q.push({x, y});
  queue<long long> r;
  r.push(0);
  while (!q.empty()) {
    pair<long long, long long> xp = q.front();
    q.pop();
    long long lpp = r.front();
    r.pop();
    long long cor[4][2];
    cor[0][0] = xp.first - 1;
    cor[0][1] = xp.second;
    cor[1][0] = xp.first + 1;
    cor[1][1] = xp.second;
    cor[2][0] = xp.first;
    cor[2][1] = xp.second - 1;
    cor[3][0] = xp.first;
    cor[3][1] = xp.second + 1;
    for (long long i = 0; i < 4; ++i) {
      if (cor[i][0] < 0 || cor[i][0] >= h) continue;
      if (cor[i][1] < 0 || cor[i][1] >= w) continue;
      if (s[cor[i][0]][cor[i][1]] == '#') continue;
      if (!vis[cor[i][0]][cor[i][1]]) {
        q.push({cor[i][0], cor[i][1]});
        r.push(lpp + 1);
      }
    }
    level[xp.first][xp.second] = lpp;
    vis[xp.first][xp.second] = true;
  }
}
void solve() {
  cin >> h >> w;
  for (long long i = 0; i < h; ++i) cin >> s[i];
  for (long long i = 0; i < h; ++i)
    for (long long j = 0; j < w; ++j)
      if (s[i][j] == '.') {
        for (long long ii = 0; ii < h; ++ii)
          for (long long jj = 0; jj < w; ++jj) {
            vis[ii][jj] = false;
            level[ii][jj] = 0;
          }
        dfs(i, j);
        for (long long ii = 0; ii < h; ++ii) {
          for (long long jj = 0; jj < w; ++jj) {
            mx = max(mx, level[ii][jj]);
          }
        }
      }
  cout << mx;
}
int32_t main() {
  mod = 1e+7;
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
