#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, 1, 0, -1};
int h, w;
vector<string> s;
vector<int> steps;
void bfs(pair<int, int> st, pair<int, int> gl) {
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<pair<int, int>> q;
  auto push = [&](pair<int, int> now, int d) {
    int y = now.first;
    int x = now.second;
    if (dist.at(y).at(x) != INF) return;
    dist.at(y).at(x) = d;
    q.push(now);
  };
  push(st, 0);
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    int y = now.first;
    int x = now.second;
    int d = dist.at(y).at(x);
    for (int i = 0; i < (int)4; ++i) {
      int nowy = y + dy.at(i);
      int nowx = x + dx.at(i);
      if (nowy >= 0 && nowy < h && nowx >= 0 && nowx < w &&
          s.at(nowy).at(nowx) != '#') {
        push(make_pair(nowy, nowx), d + 1);
      }
    }
    int gy = gl.first;
    int gx = gl.second;
    if (dist.at(gy).at(gx) != INF) {
      steps.push_back(dist.at(gy).at(gx));
    }
  }
}
int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < (int)h; ++i) cin >> s.at(i);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s.at(i).at(j) == '.') {
        for (int k = 0; k < h; ++k) {
          for (int l = 0; l < w; ++l) {
            if (k == i && l == j) continue;
            if (s.at(k).at(l) == '#') continue;
            pair<int, int> st = make_pair(i, j);
            pair<int, int> gl = make_pair(k, l);
            bfs(st, gl);
          }
        }
      }
    }
  }
  sort(steps.begin(), steps.end());
  cout << steps.back() << endl;
  return 0;
}
