#include <bits/stdc++.h>
using namespace std;
const int INF = 100;
char maze[22][22];
int n, m;
int d[22][22];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int sx, int sy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) d[i][j] = INF;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < (4); i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < n && 0 <= ny && ny < m && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      if (d[i][j] == INF) continue;
      res = max(res, d[i][j]);
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) cin >> maze[i][j];
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      if (maze[i][j] == INF) continue;
      int tmp = bfs(i, j);
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}
