#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7LL;
const int INF = 2e9;
int H, W;
char s[21][21];
int dp[21][21];
int dh[4] = {1, 0, -1, 0}, dw[4] = {0, 1, 0, -1};
pair<pair<int, int>, int> bfs(int sh, int sw) {
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j) dp[i][j] = -1;
  dp[sh][sw] = 0;
  queue<pair<pair<int, int>, int> > que;
  que.push(pair<pair<int, int>, int>(make_pair(sh, sw), 0));
  int max_cnt = 0;
  int max_h = sh, max_w = sw;
  while (!que.empty()) {
    pair<pair<int, int>, int> p = que.front();
    que.pop();
    int h = p.first.first, w = p.first.second, cnt = p.second;
    for (int i = 0; i < 4; ++i) {
      int nh = h + dh[i], nw = w + dw[i];
      if ((nh < 0) || (nh >= H) || (nw < 0) || (nw >= W)) continue;
      if (s[nh][nw] == '#') continue;
      if (dp[nh][nw] != -1) continue;
      que.push(pair<pair<int, int>, int>(make_pair(nh, nw), cnt + 1));
      dp[nh][nw] = cnt + 1;
      max_cnt = cnt + 1;
      max_h = nh;
      max_w = nw;
    }
  }
  return pair<pair<int, int>, int>(make_pair(max_h, max_w), max_cnt);
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> H >> W;
  int sh, sw;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> s[i][j];
      if (s[i][j] == '.') {
        sh = i;
        sw = j;
      }
    }
  }
  int ans = 0;
  while (true) {
    pair<pair<int, int>, int> p = bfs(sh, sw);
    if (p.second == ans) break;
    ans = p.second;
    sh = p.first.first;
    sw = p.first.second;
  }
  cout << ans << endl;
  return 0;
}
