#include <bits/stdc++.h>
using namespace std;
int calc_dst(pair<int, int> start, pair<int, int> goal,
             vector<vector<int>> meiro) {
  queue<pair<int, pair<int, int>>> que;
  que.push(
      pair<int, pair<int, int>>(0, pair<int, int>(start.first, start.second)));
  while (!que.empty()) {
    pair<int, pair<int, int>> ptr = que.front();
    que.pop();
    int dst = ptr.first;
    int hi = ptr.second.first;
    int wj = ptr.second.second;
    if (hi == goal.first & wj == goal.second) return dst;
    if (meiro[hi - 1][wj] == 0)
      que.push(pair<int, pair<int, int>>(dst + 1, pair<int, int>(hi - 1, wj)));
    if (meiro[hi + 1][wj] == 0)
      que.push(pair<int, pair<int, int>>(dst + 1, pair<int, int>(hi + 1, wj)));
    if (meiro[hi][wj - 1] == 0)
      que.push(pair<int, pair<int, int>>(dst + 1, pair<int, int>(hi, wj - 1)));
    if (meiro[hi][wj + 1] == 0)
      que.push(pair<int, pair<int, int>>(dst + 1, pair<int, int>(hi, wj + 1)));
  }
  return 0;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> meiro(h + 2, vector<int>(w + 2, 1));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char sij;
      cin >> sij;
      if (sij == '.') meiro[i][j] = 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      for (int x = 1; x <= h; x++) {
        for (int y = 1; y <= w; y++) {
          if (meiro[i][j] == 0 & meiro[x][y] == 0) {
            pair<int, int> start(i, j);
            pair<int, int> goal(x, y);
            ans = max(ans, calc_dst(start, goal, meiro));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
