#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using namespace std;
struct Corr {
  int y;
  int x;
  int depth;
};
int H, W;
int s_y, s_x, g_y, g_x;
int y, x, depth;
vector<string> vec;
vector<string> vec_origin;
queue<Corr> q;
int max_depth;
vector<int> y_vec = {0, 0, -1, +1};
vector<int> x_vec = {-1, +1, 0, 0};
int bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    max_depth = max(max_depth, depth);
    for (int i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.x <= W - 1 &&
          vec[next.y][next.x] == '.') {
        vec[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return 0;
}
int main() {
  cin >> H >> W;
  vec_origin.resize(H);
  for (int i = 0; i < (H); ++i) {
    cin >> vec_origin[i];
  }
  int ans = 0;
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      if (vec_origin[i][j] == '.') {
        max_depth = 0;
        vec = vec_origin;
        Corr start = {i, j, 0};
        q.emplace(start);
        bfs();
        ans = max(ans, max_depth);
      }
    }
  }
  cout << (ans) << endl;
  ;
  return 0;
}
