#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1LL << 30;
int H, W;
char maze[30][310];
int d[30][30];
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 < (H); i++) {
    for (int j = 0; j < (W); j++) {
      d[i][j] = INF;
    }
  }
  int res = 0;
  que.push(make_pair(sx, sy));
  d[sx][sy] = 0;
  while (!que.empty()) {
    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 < H && 0 <= ny && ny < W && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(make_pair(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        res = max(res, d[nx][ny]);
      }
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
}
