#include <bits/stdc++.h>
const double PI = 3.1415926;
const int KL = 1e6;
using namespace std;
int n, m, le, x, y;
char s[25][25];
vector<int> vec[1000];
queue<int> level;
bool vis[1000];
void bfs(int src) {
  level.push(src);
  le = 0;
  vis[src] = true;
  while (!level.empty()) {
    int sz = level.size();
    while (sz--) {
      int node = level.front();
      level.pop();
      for (int k = 0; k < vec[node].size(); k++) {
        int child = vec[node][k];
        if (!vis[child]) {
          vis[child] = true;
          level.push(child);
        }
      }
    }
    le++;
  }
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      x = (i - 1) * m + j;
      if (j < m && s[i][j + 1] != '#' && s[i][j] != '#')
        vec[x].push_back((i - 1) * m + j + 1);
      if (j > 1 && s[i][j - 1] != '#' && s[i][j] != '#')
        vec[x].push_back((i - 1) * m + j - 1);
      if (i < n && s[i + 1][j] != '#' && s[i][j] != '#')
        vec[x].push_back(i * m + j);
      if (i > 1 && s[i - 1][j] != '#' && s[i][j] != '#')
        vec[x].push_back((i - 2) * m + j);
    }
  }
  int mx = -1;
  for (int i = 1; i <= n * m; i++) {
    x = i / m + 1;
    y = i % m;
    if (s[x][y] != '#') {
      bfs(i);
      mx = max(le - 1, mx);
    }
    memset(vis, 0, sizeof vis);
  }
  cout << mx;
  return 0;
}
