#include <bits/stdc++.h>
using namespace std;
void dbg(vector<vector<char>> &m, vector<vector<bool>> &d,
         vector<vector<int>> &l) {
  int H, W;
  H = m.size() - 2;
  W = m[0].size() - 2;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << l[i][j];
    }
    cout << endl;
  }
  cout << endl;
}
int nx[] = {-1, 0, 1, 0};
int ny[] = {0, -1, 0, 1};
int solve(vector<vector<char>> &maze, int x, int y) {
  queue<pair<int, int>> q;
  vector<vector<bool>> discovered(maze.size(),
                                  vector<bool>(maze[0].size(), false));
  vector<vector<int>> len(maze.size(), vector<int>(maze[0].size(), 0));
  int ret = 0;
  q.push(make_pair(x, y));
  discovered[y][x] = true;
  len[y][x] = 0;
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      auto next = make_pair(now.first + nx[i], now.second + ny[i]);
      if (!discovered[next.second][next.first] &&
          maze[next.second][next.first] == '.') {
        discovered[next.second][next.first] = true;
        len[next.second][next.first] = len[now.second][now.first] + 1;
        ret = max(ret, len[next.second][next.first]);
        q.push(next);
      }
    }
  }
  return ret;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
  for (int i = 1; i <= H; i++) {
    string l;
    cin >> l;
    for (int j = 1; j <= W; j++) {
      maze[i][j] = l[j - 1];
    }
  }
  int ans = 0;
  for (int y = 1; y <= H; y++) {
    for (int x = 1; x <= W; x++) {
      ans = max(ans, solve(maze, x, y));
    }
  }
  cout << ans << endl;
}
