#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char> > mat(H, vector<char>(W));
  int cnt_black = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> mat.at(i).at(j);
      if (mat.at(i).at(j) == '#') {
      }
    }
  }
  int max_dist = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      queue<pair<int, int> > q;
      q.push(make_pair(i, j));
      vector<vector<int> > ans(H, vector<int>(W, -1));
      ans.at(i).at(j) = 0;
      int x, y, nx, ny;
      int tmp_max = 0;
      while (!q.empty()) {
        cerr << q.front().first << endl;
        cerr << q.front().second << endl;
        x = q.front().first;
        y = q.front().second;
        q.pop();
        for (int k = 0; k < 4; k++) {
          nx = x + dx[k];
          ny = y + dy[k];
          if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
            continue;
          }
          if (mat.at(nx).at(ny) == '#' || ans.at(nx).at(ny) != -1) {
            continue;
          }
          ans.at(nx).at(ny) = ans.at(x).at(y) + 1;
          tmp_max = max(tmp_max, ans.at(nx).at(ny));
          q.push(make_pair(nx, ny));
        }
      }
      max_dist = max(max_dist, tmp_max);
    }
  }
  cout << max_dist << endl;
}
