#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const int INF = 0x3fffffff;
int h, w;
vector<string> s;
vector<vector<int>> bfs(int x, int y) {
  vector<vector<int>> cost(h, vector<int>(h, INF));
  cost[x][y] = 0;
  queue<pair<int, int>> q;
  q.emplace(x, y);
  while (q.size()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x2 = x + dx[i], y2 = y + dy[i];
      if (x2 < 0 || x2 >= h || y2 < 0 || y2 >= w || s[x2][y2] == '#') continue;
      if (cost[x2][y2] > cost[x][y] + 1) {
        cost[x2][y2] = cost[x][y] + 1;
        q.emplace(x2, y2);
      }
    }
  }
  return cost;
}
int main() {
  cin >> h >> w;
  s.resize(h);
  for (auto&& i : s) cin >> i;
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] != '#')
        for (auto&& v : bfs(i, j))
          for (auto&& w : v)
            if (ans > w) ans = w;
  cout << ans << endl;
}
