#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline T powerM(T a, T b) {
  if (b == 0) return a;
  T tmp = powerM(a, b / 2);
  if (b % 2 == 0)
    return tmp * tmp % MOD;
  else
    return tmp * tmp % MOD * a % MOD;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  for (int i = 0; i < H; i++) cin >> maze.at(i);
  int roadi, roadj;
  vector<vector<int>> wall(H, vector<int>(W, 0));
  vector<int> dx = {0, 1, 0, -1};
  vector<int> dy = {1, 0, -1, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (maze.at(i).at(j) == '#') {
        wall.at(i).at(j) = 100;
        continue;
      }
      for (int k = 0; k < 4; k++) {
        int di = i + dy.at(k), dj = j + dx.at(k);
        if (di < 0 || di >= H || dj < 0 || dj >= W) continue;
        if (maze.at(di).at(dj) == '.') wall.at(di).at(dj)++;
      }
    }
  }
  int minwall = 4;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (wall.at(i).at(j) < minwall) {
        minwall = wall.at(i).at(j);
        roadi = i, roadj = j;
      }
    }
  }
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  dist.at(roadi).at(roadj) = 0;
  que.push(make_pair(roadi, roadj));
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int y = v.first + dy.at(i), x = v.second + dx.at(i);
      if (y < 0 || y >= H || x < 0 || x >= W) continue;
      if (maze.at(y).at(x) == '#') continue;
      if (dist.at(y).at(x) != -1) continue;
      dist.at(y).at(x) = dist.at(v.first).at(v.second) + 1;
      que.push(make_pair(y, x));
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (maze.at(i).at(j) == '#') continue;
      int tmp = dist.at(i).at(j);
      if (tmp > ans) ans = tmp;
    }
  }
  cout << ans << endl;
}
