#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e5;
int maze_solve(const pair<int, int> start, const pair<int, int> goal,
               const char s[20][20], const int h, const int w) {
  int d[20][20];
  for (ll i = 0; i < (ll)(20); i++)
    for (ll j = 0; j < (ll)(20); j++) d[i][j] = INF;
  d[start.first][start.second] = 0;
  vector<pair<int, int> > now, next;
  now.push_back(start);
  int ct = 0;
  while (true) {
    for (auto x : now) {
      for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
          if ((i == 0 && j != 0) || (i != 0 && j == 0)) {
            int nx = x.first + i;
            int ny = x.second + j;
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] == '.' &&
                d[nx][ny] == INF) {
              d[nx][ny] = ct + 1;
              next.push_back(make_pair(nx, ny));
              if (nx == goal.first && ny == goal.second) return ct + 1;
            }
          }
        }
      }
    }
    now.clear();
    now.resize(next.size());
    now = next;
    next.clear();
    ct++;
  }
}
int main() {
  int h, w;
  cin >> h >> w;
  char s[20][20];
  for (ll i = 0; i < (ll)(h); i++)
    for (ll j = 0; j < (ll)(w); j++) cin >> s[i][j];
  pair<int, int> start, goal;
  int mx = 0;
  for (ll i = 0; i < (ll)(h); i++)
    for (ll j = 0; j < (ll)(w); j++) {
      start = make_pair(i, j);
      for (ll k = 0; k < (ll)(h); k++)
        for (ll l = 0; l < (ll)(w); l++) {
          if ((k == i && l == j) || s[k][l] == '#') continue;
          goal = make_pair(k, l);
          chmax(mx, maze_solve(start, goal, s, h, w));
        }
    }
  cout << mx << endl;
  return 0;
}
