#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
int ctoi(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
bool pairCompare(const pll firstElof, pll secondElof) {
  return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
ll i, j, k, l, m, n;
ll N, M, K, H, W, L;
ll MOD = 1000000007;
ll ans = 0;
ll ans2 = 0;
ll INF = 9999999999999;
vll flag, color;
vll path;
vl A, T;
vll D;
vector<string> S;
void bfs(ll h, ll w) {
  queue<pll> Q;
  Q.push(make_pair(h, w));
  pll u;
  while (!Q.empty()) {
    u = Q.front();
    ans = max(ans, D[u.first][u.second]);
    flag[u.first][u.second] = 1;
    Q.pop();
    if (u.first != 0) {
      if (S[u.first - 1][u.second] == '.' && flag[u.first - 1][u.second] == 0) {
        Q.push(make_pair(u.first - 1, u.second));
        D[u.first - 1][u.second] = D[u.first][u.second] + 1;
      }
    }
    if (u.first != H - 1) {
      if (S[u.first + 1][u.second] == '.' && flag[u.first + 1][u.second] == 0) {
        Q.push(make_pair(u.first + 1, u.second));
        D[u.first + 1][u.second] = D[u.first][u.second] + 1;
      }
    }
    if (u.second != 0) {
      if (S[u.first][u.second - 1] == '.' && flag[u.first][u.second - 1] == 0) {
        Q.push(make_pair(u.first, u.second - 1));
        D[u.first][u.second - 1] = D[u.first][u.second] + 1;
      }
    }
    if (u.second != W - 1) {
      if (S[u.first][u.second + 1] == '.' && flag[u.first][u.second + 1] == 0) {
        Q.push(make_pair(u.first, u.second + 1));
        D[u.first][u.second + 1] = D[u.first][u.second] + 1;
      }
    }
  }
}
int main() {
  cin >> H >> W;
  flag.resize(H);
  D.resize(H);
  for (i = 0; i < H; i++) {
    flag[i].resize(W);
    D[i].resize(W);
  }
  for (i = 0; i < H; i++) {
    string s;
    cin >> s;
    S.push_back(s);
  }
  for (l = 0; l < W; l++) {
    flag[k][l] = 0;
    D[k][l] = 0;
  }
  bfs(0, 0);
  cout << ans;
}
