#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const long long MOD2 = 998244353;
const long long N = 1000 * 100 + 5;
const long long N2 = 2000 * 1000 * 10;
const long double PI = 3.14159265;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p = INF) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
string s[25];
bool vis[25][25];
long long dist[25][25];
long long h, w;
void dfs(long long x, long long y, long long dist1) {
  if (x < 0 || y < 0 || x >= h || y >= w || s[x][y] == '#' ||
      dist1 >= dist[x][y])
    return;
  dist[x][y] = dist1;
  if (!vis[x + 1][y]) {
    dfs(x + 1, y, dist1 + 1);
  }
  if (!vis[x - 1][y]) {
    dfs(x - 1, y, dist1 + 1);
  }
  if (!vis[x][y + 1]) {
    dfs(x, y + 1, dist1 + 1);
  }
  if (!vis[x][y - 1]) {
    dfs(x, y - 1, dist1 + 1);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (long long i = 0; i < h; ++i) {
    cin >> s[i];
  }
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      dist[i][j] = 110000;
    }
  }
  dfs(0, 0, 0);
  long long xreq = 0, yreq = 0, distreq = -1;
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      if (dist[i][j] > distreq && dist[i][j] != 110000) {
        xreq = i;
        yreq = j;
        distreq = dist[i][j];
      }
    }
  }
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      dist[i][j] = 110000;
    }
  }
  long long ans = 0;
  dfs(xreq, yreq, 0);
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      if (dist[i][j] > ans && dist[i][j] != 110000) {
        ans = dist[i][j];
      }
    }
  }
  cout << ans;
  return 0;
}
