#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int H, W;
vector<string> table;
vector<vector<int>> used;
pair<int, int> start;
int bfs(int y, int x) {
  queue<pair<int, int>> que;
  que.push(make_pair(y, x));
  used[y][x] = 0;
  while (not que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (ny < 0 or nx < 0 or ny >= H or nx >= W) continue;
      if (table[ny][nx] == '#') continue;
      if (used[ny][nx]) continue;
      used[ny][nx] = used[p.first][p.second] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res = max(res, used[i][j]);
      used[i][j] = 0;
    }
  }
  return res;
}
signed main(void) {
  cin >> H >> W;
  table.resize(H);
  used.resize(H, vector<int>(W, 0));
  for (int i = 0; i < H; i++) cin >> table[i];
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (table[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
