#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 20;
string s[N];
int d[N][N];
int h, w;
int _di[4] = {1, -1, 0, 0}, _dj[4] = {0, 0, 1, -1};
void bfs(pair<int, int> p) {
  queue<pair<int, int> > Q;
  Q.push(p);
  while (!Q.empty()) {
    pair<int, int> p1 = Q.front();
    Q.pop();
    int i = p1.first, j = p1.second;
    for (int k = 0; k < 4; k++) {
      int di = _di[k], dj = _dj[k];
      if (i + di < 0 || i + di > h - 1 || j + dj < 0 || j + dj > w - 1)
        continue;
      if (s[i + di][j + dj] == '#') continue;
      if (d[i + di][j + dj] > d[i][j] + 1) {
        d[i + di][j + dj] = d[i][j] + 1;
        Q.push(pair<int, int>(i + di, j + dj));
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  pair<int, int> st;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.') {
        st.first = i;
        st.second = j;
        break;
      }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = INF;
  d[st.first][st.second] = 0;
  bfs(st);
  while (true) {
    bool flag = false;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        if (s[i][j] == '.' && d[i][j] == INF) {
          flag = true;
          d[i][j] = 0;
          pair<int, int> st2;
          st2.first = i;
          st2.second = j;
          bfs(st2);
        }
    if (!flag) break;
  }
  int max_d = 0;
  pair<int, int> p;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.' && d[i][j] > max_d) {
        max_d = d[i][j];
        p.first = i;
        p.second = j;
      }
    }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = INF;
  d[p.first][p.second] = 0;
  bfs(p);
  max_d = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.') max_d = max(max_d, d[i][j]);
  cout << max_d << endl;
}
