#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;
int maze() {
  int H, W;
  cin >> H >> W;
  vector<string> data(H);
  for (int i = 0; i < H; i++) {
    cin >> data[i];
  }
  queue<vector<int>> d_queue;
  int count = 0;
  int ans = 0;
  vector<pair<int, int>> move = {
      {0, 1},
      {1, 0},
      {-1, 0},
      {0, -1},
  };
  for (int k = 0; k < H; k++) {
    for (int l = 0; l < W; l++) {
      if (data[k].at(l) != '#') {
        d_queue.push({k, l, count});
        vector<string> temp_data = data;
        while (!d_queue.empty()) {
          vector<int> now_queue = d_queue.front();
          d_queue.pop();
          for (pair<int, int> move_array : move) {
            temp_data[now_queue[0]][now_queue[1]] = '#';
            if (0 <= now_queue[0] + move_array.first &&
                now_queue[0] + move_array.first < H &&
                0 <= now_queue[1] + move_array.second &&
                now_queue[1] + move_array.second < W) {
              if (temp_data[now_queue[0] + move_array.first]
                           [now_queue[1] + move_array.second] == '.') {
                d_queue.push({now_queue[0] + move_array.first,
                              now_queue[1] + move_array.second,
                              now_queue[2] + 1});
                ans = max(ans, now_queue[2] + 1);
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
int main() { maze(); }
