#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long double PI = acosl(-1);
const long long infl = 1e17;
const int inf = 2e9 + 100;
const int nmax = 2e5 + 10;
const int MAXLG = log2(nmax) + 1;
int h, w;
vector<string> s;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool thikase(int i, int j) {
  if (i < h and i >= 0 and j < w and j >= 0 and s[i][j] != '#') return true;
  return false;
}
int work(pair<int, int> sorc, pair<int, int> dst) {
  vector<vector<int> > d(h, vector<int>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = inf;
  queue<pair<int, int> > q;
  q.push(sorc);
  d[sorc.first][sorc.second] = 0;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    int i1 = u.first, j1 = u.second;
    for (int k = 0; k < 4; k++) {
      if (thikase(i1 + dx[k], j1 + dy[k]) and
          d[i1 + dx[k]][j1 + dy[k]] > d[i1][j1] + 1) {
        q.push({i1 + dx[k], j1 + dy[k]}),
            d[i1 + dx[k]][j1 + dy[k]] = d[i1][j1] + 1;
      }
    }
  }
  return d[dst.first][dst.second];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  s.resize(h);
  for (auto &z : s) cin >> z;
  int ret = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int i2 = 0; i2 < h; i2++) {
        for (int j2 = 0; j2 < w; j2++) {
          if (s[i][j] == '.' and s[i2][j2] == '.') {
            ret = max(ret, work({i, j}, {i2, j2}));
          }
        }
      }
    }
  }
  cout << ret << endl;
}
