#include <bits/stdc++.h>
const int INF = 1001001001;
using namespace std;
int main() {
  long long H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (long long i = 0; i < H; i += 1) {
    for (long long j = 0; j < W; j += 1) {
      cin >> A[i][j];
    }
  }
  vector<long long> B(H * W);
  for (long long sv = 0; sv < H * W; sv += 1) {
    vector<long long> dist(H * W, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (A[v / H + 1][v % H] == '.') push(v + 1, d + 1);
      if (A[v / H - 1][v % H] == '.') push(v - 1, d + 1);
      if (A[v / H][v % H + 1] == '.') push(v + H, d + 1);
      if (A[v / H][v % H - 1] == '.') push(v - H, d + 1);
    }
    sort(dist.begin(), dist.end());
    B[sv] = dist[0];
  }
  sort(B.begin(), B.end());
  cout << B[0] << endl;
}
