#include <bits/stdc++.h>
using namespace std;
const int mx = 25;
int h, w;
char grid[mx][mx];
bool visited[mx][mx];
int dist[mx][mx];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool valid(int row, int col) {
  return (row >= 0 and row < h and col >= 0 and col < w and
          visited[row][col] == false and grid[row][col] == '.');
}
void bfs(int r, int c) {
  queue<pair<int, int> > cells;
  cells.push(make_pair(r, c));
  visited[r][c] = true;
  dist[r][c] = 0;
  while (!cells.empty()) {
    auto now = cells.front();
    cells.pop();
    for (int dir = 0; dir < 4; dir++) {
      int row = dx[dir] + now.first;
      int col = dy[dir] + now.second;
      if (valid(row, col)) {
        dist[row][col] = dist[now.first][now.second] + 1;
        visited[row][col] = true;
        cells.push(make_pair(row, col));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  int x[4] = {0, 0, h - 1, h - 1};
  int y[4] = {0, w - 1, 0, w - 1};
  for (int ok = 0; ok < 4; ok++) {
    int row = x[ok];
    int col = y[ok];
    if (grid[row][col] == '#') continue;
    memset(visited, false, sizeof(visited));
    memset(dist, 0, sizeof(dist));
    bfs(row, col);
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        ans = max(ans, dist[i][j]);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
