#include <bits/stdc++.h>
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
using namespace std;
void file() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool vis[20][20];
char ar[20][20];
int n, m, ans = 0;
bool valid(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m); }
bool switchMode = 0;
void bfs(int x, int y) {
  memset(vis, 0, sizeof vis);
  queue<pair<int, pair<int, int> > > q;
  q.push({0, {x, y}});
  vis[x][y] = 1;
  int dist = 0, x1, y1;
  while (q.size()) {
    dist = q.front().first;
    x1 = q.front().second.first;
    y1 = q.front().second.second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x2 = x1 + dx[i], y2 = y1 + dy[i];
      if (valid(x2, y2) && !vis[x2][y2] && ar[x2][y2] == '.') {
        vis[x2][y2] = 1;
        q.push({dist + 1, {x2, y2}});
      }
    }
  }
  if (switchMode == 0) {
    switchMode = 1;
    bfs(x1, y1);
  } else
    ans = dist;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int k = 0; k < m; k++) cin >> ar[i][k];
  for (int i = 0; i < n; i++)
    for (int k = 0; k < m; k++)
      if (ar[i][k] == '.') {
        bfs(i, k);
        return cout << ans << '\n', 0;
      }
}
