#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int H, W;
char maze[20][20];
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs(int sx, int sy, int gx, int gy) {
  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], 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;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }
  int bx[2 * H + 2 * W];
  int by[2 * H + 2 * W];
  for (int i = 0; i < H; i++) {
    bx[i] = i;
    by[i] = 0;
  }
  for (int i = 0; i < H; i++) {
    bx[i + H] = i;
    by[i + H] = W - 1;
  }
  for (int i = 0; i < W; i++) {
    bx[i + 2 * H] = 0;
    by[i + 2 * H] = i;
  }
  for (int i = 0; i < W; i++) {
    bx[i + 2 * H + W] = H - 1;
    by[i + 2 * H + W] = i;
  }
  int ans = 0;
  for (int i = 0; i < 2 * H + 2 * W; i++) {
    for (int j = 0; j < 2 * H + 2 * W; j++) {
      if (maze[bx[i]][by[i]] != '#' && maze[bx[j]][by[j]] != '#' &&
          bfs(bx[i], by[i], bx[j], by[j]) != INF) {
        ans = max(ans, bfs(bx[i], by[i], bx[j], by[j]));
      }
    }
  }
  cout << ans << endl;
}
