#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
template <class T>
inline T sum(vector<T>& vec) {
  T res = 0;
  for (int i = 0; i < vec.size(); i++) res += vec[i];
  return res;
}
template <class T>
inline T mpow(T a, T b) {
  if (b == 0) return 1;
  T c = mpow(a, b / 2);
  if (b % 2 == 1) return c * c * a;
  return c * c;
}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
int H, W;
int d1[20][20];
int d2[20][20];
vector<string> S(20);
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
void bfs(int x, int y) {
  queue<pair<int, int> > que;
  que.push(make_pair(x, y));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int(i) = 0; (i) < (4); (i)++) {
      int a = p.first + dx[i], b = p.second + dy[i];
      if (a >= 0 && a < H && b >= 0 && b < W && d1[a][b] == -1 &&
          S[a][b] == '.') {
        d1[a][b] = d1[p.first][p.second] + 1;
        que.push(make_pair(a, b));
      }
    }
  }
}
void bfs2(int x, int y) {
  queue<pair<int, int> > que;
  que.push(make_pair(x, y));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int(i) = 0; (i) < (4); (i)++) {
      int a = p.first + dx[i], b = p.second + dy[i];
      if (a >= 0 && a < H && b >= 0 && b < W && d2[a][b] == -1 &&
          S[a][b] == '.') {
        d2[a][b] = d2[p.first][p.second] + 1;
        que.push(make_pair(a, b));
      }
    }
  }
}
int main() {
  cin >> H >> W;
  for (int(i) = 0; (i) < (H); (i)++) cin >> S[i];
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) d1[i][j] = d2[i][j] = -1;
  }
  bool flag = true;
  for (int(i) = 0; (i) < (H); (i)++) {
    if (!flag) break;
    for (int(j) = 0; (j) < (W); (j)++) {
      if (S[i][j] == '.') {
        d1[i][j] = 0;
        bfs(i, j);
        flag = false;
        break;
      }
    }
  }
  int maxi, maxj, m = -1;
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      if (d1[i][j] > m) {
        m = d1[i][j];
        maxi = i, maxj = j;
      }
    }
  }
  d2[maxi][maxj] = 0;
  bfs2(maxi, maxj);
  int res = -1;
  for (int(i) = 0; (i) < (H); (i)++) {
    for (int(j) = 0; (j) < (W); (j)++) {
      chmax(res, d2[i][j]);
    }
  }
  cout << res << endl;
}
