#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, -1, 1};
int n, m;
char c[MAXN][MAXN];
bool used[MAXN][MAXN];
int dist[MAXN][MAXN];
queue<pair<int, int> > q;
int si, sj;
int main() {
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &c[i][j]);
      if (c[i][j] == '.') {
        si = i;
        sj = j;
      }
    }
    scanf("\n");
  }
  used[si][sj] = true;
  q.push({si, sj});
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int ci = p.first + di[k];
      int cj = p.second + dj[k];
      if (ci < 0 || ci >= n || cj < 0 || cj >= m || c[ci][cj] == '#' ||
          used[ci][cj]) {
        continue;
      }
      used[ci][cj] = true;
      dist[ci][cj] = dist[p.first][p.second] + 1;
      q.push({ci, cj});
    }
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dist[i][j] > mx) {
        mx = dist[i][j];
        si = i;
        sj = j;
      }
    }
  }
  memset(used, false, sizeof(used));
  memset(dist, 0, sizeof(dist));
  used[si][sj] = true;
  q.push({si, sj});
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int ci = p.first + di[k];
      int cj = p.second + dj[k];
      if (ci < 0 || ci >= n || cj < 0 || cj >= m || c[ci][cj] == '#' ||
          used[ci][cj]) {
        continue;
      }
      used[ci][cj] = true;
      dist[ci][cj] = dist[p.first][p.second] + 1;
      q.push({ci, cj});
    }
  }
  mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dist[i][j] > mx) {
        mx = dist[i][j];
      }
    }
  }
  cout << mx << endl;
  return 0;
}
