#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 100000000;
const int MAX_N = 20;
const int MAX_M = 20;
char maze[MAX_N][MAX_M + 1];
int h, w;
int sx, sy;
int gx, gy;
int d[MAX_N][MAX_M];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vector<int> ans;
int bfs() {
  queue<pair<int, int> > que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  cin >> h >> w;
  if (h == 1 && w == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = (int)0; i < (int)h; ++i) {
    for (int j = (int)0; j < (int)w; ++j) {
      cin >> maze[i][j];
    }
  }
  for (int i = (int)0; i < (int)h; ++i) {
    for (int j = (int)0; j < (int)w; ++j) {
      if (maze[i][j] == '.') {
        sx = i, sy = j;
      }
      for (int k = (int)0; k < (int)h; ++k) {
        for (int l = (int)0; l < (int)w; ++l) {
          if (maze[k][l] == '.' && i != k && j != l) {
            gx = k, gy = l;
            int res = bfs();
            ans.push_back(res);
          }
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  int size = ans.size() - 1;
  cout << ans[size] << endl;
  return 0;
}
