#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::list;
using std::memset;
using std::string;
static int const MAXSIZE = 20;
static char road[MAXSIZE][MAXSIZE] = {0};
static int distance[MAXSIZE][MAXSIZE] = {0};
static int y_last = 0;
static int x_last = 0;
static int d_last = 0;
static list<int> q;
static int H = 0;
static int W = 0;
static void trial_yx(int y, int x, int d) {
  if (0 <= y && y < H && 0 <= x && x < W && road[y][x] && distance[y][x] == 0) {
    distance[y][x] = d + 1;
    y_last = y;
    x_last = x;
    d_last = d + 1;
    q.push_back(y);
    q.push_back(x);
  }
}
static void trial(int y_start, int x_start) {
  memset((void *)distance, 0, sizeof(distance));
  q.push_back(y_start);
  q.push_back(x_start);
  while (!q.empty()) {
    int y = q.front();
    q.pop_front();
    int x = q.front();
    q.pop_front();
    int d = distance[y][x];
    distance[y][x] = -1;
    trial_yx(y - 1, x, d);
    trial_yx(y + 1, x, d);
    trial_yx(y, x - 1, d);
    trial_yx(y, x + 1, d);
  }
}
int main() {
  cin >> H >> W;
  string S;
  int xx = 0;
  int yy = 0;
  for (int y = 0; y < H; y++) {
    cin >> S;
    for (int x = 0; x < W; x++) {
      road[y][x] = (S[x] == '.' ? 1 : 0);
      if (S[x] == '.') {
        xx = x;
        yy = y;
      }
    }
  }
  trial(yy, xx);
  trial(y_last, x_last);
  trial(y_last, x_last);
  cout << d_last << endl;
  return 0;
}
