#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
vector<string> maze(20);
int h, w, sx, sy, gx, gy;
int bfs() {
  vector<vector<int>> checked(20, vector<int>(20, (int)(1e9 + 7)));
  queue<pair<int, int>> que;
  que.push(pair<int, int>(sy, sx));
  checked[sy][sx] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gy && p.second == gx) break;
    for (int i = 0; i < 4; i++) {
      int ny = dy[i] + p.first, nx = dx[i] + p.second;
      if (0 <= ny && ny < h && 0 <= nx && nx < w && maze[ny][nx] == '.' &&
          checked[ny][nx] == (int)(1e9 + 7)) {
        que.push(pair<int, int>(ny, nx));
        checked[ny][nx] = checked[p.first][p.second] + 1;
      }
    }
  }
  return checked[gy][gx];
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> maze[i];
  vector<pair<int, int>> grids;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '.') grids.push_back(make_pair(i, j));
    }
  }
  int ans = 0;
  for (int i = 0; i <= grids.size() / 2; i++) {
    for (int j = grids.size() - 1; j >= grids.size() / 2; j--) {
      sy = grids[i].first, sx = grids[i].second;
      gy = grids[j].first, gx = grids[j].second;
      ans = max(bfs(), ans);
    }
  }
  cout << ans << endl;
}
