#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
const vector<vector<int>> dir8 = {{0, 1}, {1, 0},  {-1, 0}, {0, -1},
                                  {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> hen(h + 2, vector<bool>(w + 2));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      char tmp;
      cin >> tmp;
      hen[i][j] = tmp == '.';
    }
  int res = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (!hen[i][j]) continue;
      vector<vector<int>> dist(h + 2, vector<int>(w + 2, -1));
      queue<pair<int, int>> que;
      dist[i][j] = 0;
      que.push({i, j});
      while (que.size()) {
        auto cur = que.front();
        que.pop();
        for (auto d : dir4) {
          int y = cur.first + d[0], x = cur.second + d[1];
          if (!hen[y][x] || dist[y][x] != -1) continue;
          dist[y][x] = dist[cur.first][cur.second] + 1;
          que.push({y, x});
        }
      }
      for (int i = 0; i < h; i++)
        res = max(res, *max_element(dist[i].begin(), dist[i].end()));
    }
  }
  cout << res << endl;
}
