#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for (int i = 0; i < (H); ++i) cin >> map[i];
  int ans = 0;
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      vector<vector<int>> dist(H, vector<int>(W, -1));
      dist[i][j] = 0;
      queue<P> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        auto cur = que.front();
        int y = cur.first;
        int x = cur.second;
        que.pop();
        for (int k = 0; k < (4); ++k) {
          int next_y = y + dy[k];
          int next_x = x + dx[k];
          if (next_y < 0 || next_y >= H || next_x < 0 || next_x >= W) continue;
          if (map[next_y][next_x] == '#') continue;
          if (dist[next_y][next_x] == -1) {
            que.push(make_pair(next_y, next_x));
            dist[next_y][next_x] = dist[y][x] + 1;
          }
        }
      }
      for (int h = 0; h < (H); ++h)
        for (int w = 0; w < (W); ++w) ans = max(ans, dist[h][w]);
    }
  }
  cout << ans << endl;
}
