#include <bits/stdc++.h>
using namespace std;
int memo[25][25], n, m;
char matriz[25][25];
int gx[] = {0, 0, 1, -1};
int gy[] = {1, -1, 0, 0};
int bfs(int x, int y) {
  queue<pair<int, pair<int, int> > > fila;
  memset(memo, 0, sizeof memo);
  memo[x][y] = 1;
  int ans = -1;
  fila.push({0, {x, y}});
  while (!fila.empty()) {
    int pri = fila.front().second.first;
    int seg = fila.front().second.second;
    int dist = fila.front().first;
    ans = max(ans, dist);
    fila.pop();
    for (int i = 0; i < 4; i++) {
      int ax = pri + gx[i];
      int ay = seg + gy[i];
      if (ax > 0 && ax <= n && ay > 0 && ay <= m && matriz[ax][ay] != '#' &&
          !memo[ax][ay]) {
        memo[ax][ay] = 1;
        fila.push({dist + 1, {ax, ay}});
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> matriz[i][j];
    }
  }
  int resp = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (matriz[i][j] != '#') {
        resp = max(resp, bfs(i, j));
        if (i == 3 && j == 1) {
          cout << bfs(i, j) << "\n";
        }
      }
    }
  }
  return 0;
}
