#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<int, int, int>;
void init_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll h, w, ans = 0;
string s[22];
void bfs(int sx, int sy) {
  ll field[22][22];
  ll vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
  fill(field[0], field[22], 1000000000);
  priority_queue<TP, vector<TP>, greater<TP>> que;
  que.push(make_tuple(0, sx, sy));
  while (!que.empty()) {
    auto tmp = que.top();
    que.pop();
    ll d = get<0>(tmp);
    ll x = get<1>(tmp);
    ll y = get<2>(tmp);
    d++;
    for (int i = 0; i < 4; i++) {
      ll nx = x + vx[i];
      ll ny = y + vy[i];
      if (nx >= 0 && ny >= 0 && nx < h && ny < w && s[nx][ny] == '.') {
        if (field[nx][ny] > d) {
          field[nx][ny] = d;
          que.push(make_tuple(d, nx, ny));
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        ans = max(ans, field[i][j]);
      }
    }
  }
}
signed main() {
  init_io();
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') {
        bfs(i, j);
      }
    }
  }
  cout << ans << endl;
}
