#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MX = 2e5 + 2;
const long long INF = 1000000000000000000;
const long double PI = 4 * atan((long double)1);
const pair<int, int> dir[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int h, w;
char grid[21][21];
int dist[21][21];
int bfs(int x, int y) {
  queue<pair<int, int> > q;
  q.push({x, y});
  for (int y1 = h - 1; y1 >= 0; y1--) {
    for (int x1 = 0; x1 < w; x1++) {
      dist[x1][y1] = 0;
    }
  }
  int res = 0;
  while (!q.empty()) {
    int currX = q.front().first;
    int currY = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (currX + dir[i].first < 0 || currX + dir[i].first >= w) continue;
      if (currY + dir[i].second < 0 || currY + dir[i].second >= h) continue;
      if (grid[currX + dir[i].first][currY + dir[i].second] == '#') continue;
      if (currX + dir[i].first == x && currY + dir[i].second == y) continue;
      if (dist[currX + dir[i].first][currY + dir[i].second]) continue;
      dist[currX + dir[i].first][currY + dir[i].second] =
          dist[currX][currY] + 1;
      res = max(res, dist[currX + dir[i].first][currY + dir[i].second]);
      q.push({currX + dir[i].first, currY + dir[i].second});
    }
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> h >> w;
  for (int y = h - 1; y >= 0; y--) {
    for (int x = 0; x < w; x++) {
      cin >> grid[x][y];
    }
  }
  int ans = MX;
  for (int y = h - 1; y >= 0; y--) {
    for (int x = 0; x < w; x++) {
      if (grid[x][y] == '.') {
        ans = min(ans, bfs(x, y));
      }
    }
  }
  cout << ans;
  return 0;
}
