#include <bits/stdc++.h>
using namespace std;
const int INF = 1e7 + 10;
int a[4] = {0, 1, 0, -1};
int b[4] = {1, 0, -1, 0};
int ans1 = 0, n, m, ans = 0;
char arr[21][21];
bool check(int x, int y) {
  if ((x <= n - 1 and x >= 0) and (y >= 0 and y <= m - 1) and arr[x][y] == '.')
    return true;
  return false;
}
int bfs(int x, int y) {
  int count1 = 0;
  bool vis[21][21];
  memset(vis, false, sizeof(vis));
  queue<pair<int, pair<int, int>>> q;
  q.push(make_pair(0, make_pair(x, y)));
  vis[x][y] = true;
  while (!q.empty()) {
    auto l = q.front();
    q.pop();
    count1 = l.first;
    x = l.second.first;
    y = l.second.second;
    ans = max(ans, count1);
    for (int i = 0; i < 4; ++i) {
      if (vis[x + a[i]][y + b[i]]) continue;
      if (arr[x + a[i]][y + b[i]] == '#') vis[x + a[i]][y + b[i]] = true;
      if (check(x + a[i], y + b[i])) {
        q.push(make_pair(count1 + 1, make_pair(x + a[i], y + b[i])));
        vis[x + a[i]][y + b[i]] = true;
      }
    }
  }
  return ans;
}
int main() {
  cin >> n >> m;
  int maxi = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      maxi = bfs(i, j);
      ans1 = max(maxi, ans1);
      ans = 0;
    }
  }
  cout << ans1;
}
