#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1000000007;
ll n_pow(ll a, ll n) {
  if (n == 0) return 1;
  ll t = n_pow(a, n / 2);
  t *= t;
  t %= mod;
  if (n % 2 == 1) t *= a;
  return t % mod;
}
const int INF = 1001001001;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> dp1(h, vector<int>(w));
  vector<vector<int>> dp2(h, vector<int>(w));
  vector<vector<bool>> path(h, vector<bool>(w));
  pair<int, int> start;
  bool first = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        path[i][j] = false;
      } else {
        path[i][j] = true;
        if (first) {
          first = false;
          start.first = i;
          start.second = j;
        }
      }
      dp1[i][j] = INF;
      dp2[i][j] = INF;
    }
  }
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  dp1[start.first][start.second] = 0;
  queue<pair<int, int>> todo;
  todo.push(start);
  while (todo.empty() != 1) {
    pair<int, int> tmp = todo.front();
    todo.pop();
    for (int i = 0; i < 4; i++) {
      if (tmp.first + dy[i] >= 0 && tmp.first + dy[i] < h &&
          tmp.second + dx[i] >= 0 && tmp.second + dx[i] < w) {
        if (path[tmp.first + dy[i]][tmp.second + dx[i]]) {
          if (dp1[tmp.first + dy[i]][tmp.second + dx[i]] >
              dp1[tmp.first][tmp.second] + 1) {
            dp1[tmp.first + dy[i]][tmp.second + dx[i]] =
                dp1[tmp.first][tmp.second] + 1;
            todo.push(pair<int, int>(tmp.first + dy[i], tmp.second + dx[i]));
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (path[i][j]) {
        if (dp1[i][j] > ans) {
          ans = dp1[i][j];
          start.first = i;
          start.second = j;
        }
      }
    }
  }
  dp2[start.first][start.second] = 0;
  todo.push(start);
  while (todo.empty() != 1) {
    pair<int, int> tmp = todo.front();
    todo.pop();
    for (int i = 0; i < 4; i++) {
      if (tmp.first + dy[i] >= 0 && tmp.first + dy[i] < h &&
          tmp.second + dx[i] >= 0 && tmp.second + dx[i] < w) {
        if (path[tmp.first + dy[i]][tmp.second + dx[i]]) {
          if (dp2[tmp.first + dy[i]][tmp.second + dx[i]] >
              dp2[tmp.first][tmp.second] + 1) {
            dp2[tmp.first + dy[i]][tmp.second + dx[i]] =
                dp2[tmp.first][tmp.second] + 1;
            todo.push(pair<int, int>(tmp.first + dy[i], tmp.second + dx[i]));
          }
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (path[i][j]) {
        if (dp2[i][j] > ans) {
          ans = dp2[i][j];
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
