#include <bits/stdc++.h>
using namespace std;
const int INF = 10;
const vector<pair<int, int>> adj = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  set<pair<int, int>> visited;
  for (int i = 0; i < h; i++) {
    cin >> grid[i];
  }
  int max_dist = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '#') continue;
      vector<vector<int>> dp(h, vector<int>(w, INF));
      dp[i][j] = 0;
      visited.clear();
      queue<pair<int, int>> next;
      next.push({i, j});
      while (!next.empty()) {
        pair<int, int> coord = next.front();
        next.pop();
        max_dist = max(max_dist, dp[coord.first][coord.second]);
        if (visited.count(coord)) continue;
        visited.insert({coord.first, coord.second});
        for (auto a : adj) {
          int x = coord.first + a.first;
          int y = coord.second + a.second;
          if (x >= 0 && x < h && y >= 0 && y < w && grid[x][y] == '.') {
            dp[x][y] = min(dp[x][y], dp[coord.first][coord.second] + 1);
            next.push({x, y});
          }
        }
      }
    }
  }
  cout << max_dist << '\n';
}
