#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int h, w;
char meiro[20][20];
int visit[20][20];
void init_visit() {
  for (int i = 0; i < (20); ++i)
    for (int j = 0; j < (20); ++j) visit[i][j] = 0;
}
int find(int si, int sj, int ei, int ej) {
  if (meiro[si][sj] == '#' || meiro[ei][ej] == '#') {
    return 0;
  }
  queue<pair<int, P>> que;
  que.push({0, {si, sj}});
  P idou[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  while (true) {
    pair<int, P> now = que.front();
    que.pop();
    int row = now.second.first;
    int col = now.second.second;
    int cnt = now.first;
    for (P x : idou) {
      int nexti = row + x.first, nextj = col + x.second;
      if (nexti == ei && nextj == ej) {
        init_visit();
        return cnt + 1;
      }
      if (0 <= nexti && nexti < h && 0 <= nextj && nextj < w &&
          visit[nexti][nextj] == 0 && meiro[nexti][nextj] == '.') {
        visit[nexti][nextj] = 1;
        que.push({cnt + 1, {nexti, nextj}});
      }
    }
  }
  init_visit();
  return 0;
}
void solve() {
  cin >> h >> w;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> meiro[i][j];
  int ans = 0;
  for (int si = 0; si < (h); ++si)
    for (int sj = 0; sj < (w); ++sj)
      for (int ei = 0; ei < (h); ++ei)
        for (int ej = 0; ej < (w); ++ej) {
          ans = max(ans, find(si, sj, ei, ej));
        }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
