#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
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>
void DEBUG_DP(T* viewdp, int ilen, int jlen) {
  for (int i = 0; i < (int)(ilen); ++i) {
    for (int j = 0; j < (int)(jlen); ++j) {
      if (viewdp[i][j] != -1)
        printf("[% 4d]", viewdp[i][j]);
      else
        printf("[    ]");
    }
    puts("");
  }
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int h, w;
char mz[22][22];
int cnt[22][22];
int sx, sy;
int gx, gy;
queue<pair<int, int> > que;
int mx;
void solve() {
  mx = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < (int)(4); ++i) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if (cnt[ny][nx] != INT_MAX) continue;
      if (mz[ny][nx] == '#') continue;
      chmin(cnt[ny][nx], cnt[p.first][p.second] + 1);
      if (chmax(mx, cnt[ny][nx])) {
        sy = ny;
        sx = nx;
      }
      que.push(make_pair(ny, nx));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < (int)(h); ++i)
    for (int j = 0; j < (int)(w); ++j) cin >> mz[i][j];
  for (int i = 0; i < (int)(22); ++i) fill(cnt[i], cnt[i] + 22, INT_MAX);
  for (int i = 0; i < (int)(h); ++i)
    for (int j = 0; j < (int)(w); ++j) {
      if (mz[i][j] == '.') {
        sy = i;
        sx = j;
        break;
      }
    }
  cnt[sy][sx] = 0;
  que.push(make_pair(sy, sx));
  solve();
  for (int i = 0; i < (int)(22); ++i) fill(cnt[i], cnt[i] + 22, INT_MAX);
  cnt[sy][sx] = 0;
  que.push(make_pair(sy, sx));
  solve();
  cout << mx << endl;
  return 0;
}
