#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int N = 30;
string s[N];
int num[N][N];
int n, m, ans, res;
bool check(int x, int y) {
  if (x < 1 || y < 1 || x > n || y > m) return false;
  if (s[x][y] == '#' || num[x][y]) return false;
  if (s[x][y] == '.') return true;
}
int bfs(int xx, int yy) {
  queue<pair<int, int> > q;
  memset(num, 0, sizeof num);
  int cnt = 0;
  q.push(make_pair(xx, yy));
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    cnt = max(cnt, num[t.first][t.second]);
    int v = num[t.first][t.second];
    for (int i = 0; i < 4; i++) {
      int x = t.first + dx[i];
      int y = t.second + dy[i];
      if (!check(x, y)) continue;
      if (x != xx || y != yy) {
        num[x][y] = v + 1;
        q.push(make_pair(x, y));
      }
    }
  }
  return cnt;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= m; j++) s[i][j] = getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') continue;
      res = bfs(i, j);
      ans = max(ans, res);
    }
  }
  cout << ans << endl;
  return 0;
}
