#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; i++) cin >> s[i];
  int max_dis = 0;
  int hoko[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      queue<pair<int, int>> que;
      que.push(make_pair(j, i));
      vector<vector<int>> field(H, vector<int>(W, -1));
      field[i][j] = 0;
      while (!que.empty()) {
        pair<int, int> xy = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int n_x = xy.first + hoko[k][0];
          int n_y = xy.second + hoko[k][1];
          if (n_x < W && n_x >= 0 && n_y < H && n_y >= 0) {
            if (s[n_y][n_x] == '.') {
              if (field[n_y][n_x] == -1) {
                field[n_y][n_x] = field[xy.second][xy.first] + 1;
                que.push(make_pair(n_x, n_y));
              } else if (field[n_y][n_x] > field[xy.second][xy.first] + 1)
                que.push(make_pair(n_x, n_y));
              field[n_y][n_x] =
                  min(field[xy.second][xy.first] + 1, field[n_y][n_x]);
            }
          }
        }
      }
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          max_dis = max(max_dis, field[k][l]);
        }
      }
    }
  }
  cout << max_dis << endl;
}
