#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll po(ll a, ll b) {
  ll ans = 1;
  while (b--) ans *= a;
  return ans;
}
ll pom(ll a, ll b, ll mod) {
  if (b == 0) return 1;
  ll k = pom(a, b / 2, mod);
  if (b % 2 == 0)
    return (k * k) % mod;
  else
    return ((k * k) * mod * a) % mod;
}
ll sqdist(ll a, ll b, ll c, ll d) {
  return (a - c) * (a - c) + (b - d) * (b - d);
}
int arr[25][25];
int visited[25][25];
int dist[25][25];
int n, m;
int bfs(int p, int q) {
  queue<pair<int, int> > qq;
  qq.push(make_pair(p, q));
  visited[p][q] = 1;
  while (!qq.empty()) {
    int x[] = {0, 0, 1, -1};
    int y[] = {1, -1, 0, 0};
    int p = qq.front().first;
    int q = qq.front().second;
    qq.pop();
    for (ll i = (0); i < (4); i++) {
      int a = p + x[i], b = q + y[i];
      if (a >= 0 && a < m && b >= 0 && b < n && !visited[a][b] &&
          arr[a][b] == 0) {
        visited[a][b]++;
        dist[a][b] = dist[p][q] + 1;
        qq.push(make_pair(a, b));
      }
    }
  }
}
void solve() {
  cin >> m >> n;
  int a, b;
  for (ll i = (0); i < (m); i++) {
    string str;
    cin >> str;
    for (ll j = (0); j < (n); j++) {
      arr[i][j] = (str[j] == '.' ? 0 : 1);
      if (arr[i][j] == 0) {
        a = i;
        b = j;
      }
    }
  }
  bfs(a, b);
  int mi = 0;
  a = 0;
  b = 0;
  for (ll i = (0); i < (m); i++) {
    for (ll j = (0); j < (n); j++) {
      if (arr[i][j] == 0 && dist[i][j] >= mi) {
        mi = dist[i][j];
        a = i;
        b = j;
      }
    }
  }
  memset(dist, 0, sizeof(dist));
  memset(visited, 0, sizeof(visited));
  bfs(a, b);
  int ans = 0;
  for (ll i = (0); i < (m); i++) {
    for (ll j = (0); j < (n); j++) {
      if (arr[i][j] == 0) ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  solve();
}
