#include <bits/stdc++.h>
using namespace std;
long long n, k, m, flag, mod, cnt;
char mat[55][55];
long long vis[500005], q[500005];
vector<long long> v[400];
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long x = 0, y = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
      if (mat[i][j] == '.') {
        if ((mat[i][j - 1] == '.') and (j > 0))
          v[i * n + j - 1].push_back(n * i + j),
              v[i * n + j].push_back(i * n + j - 1);
        if ((mat[i - 1][j] == '.') and (i > 0))
          v[(i - 1) * n + j].push_back(n * i + j),
              v[i * n + j].push_back(n * i + j - n);
      }
    }
  for (int i = 0; i < n * m; ++i) {
    long long iter = 2;
    q[0] = i, q[1] = -1;
    for (int j = 0; j < iter; ++j) {
      if (vis[q[j]]) continue;
      if ((q[j] < 0) and (j != iter - 1)) q[iter++] = q[j] - 1;
      vis[q[j]] = 1;
      for (auto it : v[q[j]]) {
        if (vis[it])
          continue;
        else
          q[iter++] = it;
      }
    }
    if (mod > q[iter - 1]) mod = q[iter - 1];
    for (int i = -1 * n * m; i < n * m; ++i) vis[i] = 0, q[i] = 0;
  }
  cout << ++mod * -1 << endl;
  return 0;
}
