#include <bits/stdc++.h>
using namespace std;
vector<string> v;
long long xx = 0, yy = 0, z = 0, w = 0, n = 0, m = 0;
vector<long long> y_vec = {1, 0, -1, 0};
vector<long long> x_vec = {0, +1, 0, -1};
struct Corr {
  long long y;
  long long x;
  long long depth;
};
queue<Corr> q;
long long y, x, depth;
long long bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    for (long long i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= xx - 1 && 0 <= next.x && next.x <= yy - 1 &&
          v[next.y][next.x] == '.') {
        v[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return depth;
}
signed main() {
  std::cin >> xx >> yy;
  v.resize(xx);
  for (long long i = 0; i < (long long)(xx); ++i) {
    std::cin >> v[i];
  }
  std::vector<string> vv;
  vv = v;
  for (long long i = 0; i < (long long)(xx); ++i) {
    for (long long j = 0; j < (long long)(yy); ++j) {
      if (v[i][j] == '#') continue;
      v = vv;
      Corr start = {j, i, 0};
      q.emplace(start);
      m = bfs();
      if (w < m) w = m;
    }
  }
  cout << w << "\n";
}
