#include <bits/stdc++.h>
using namespace std;
int w, h;
char mat[20][20];
map<pair<int, int>, int> visi;
int bfs(pair<int, int> at) {
  visi[at] = 1;
  queue<pair<pair<int, int>, int>> q;
  q.push({at, 0});
  int d = 0, r = 0;
  while (!q.empty()) {
    at = q.front().first;
    d = q.front().second;
    r = max(r, d);
    if (at.first < h && !visi[make_pair(at.first + 1, at.second)] &&
        mat[at.first + 1][at.second] == '.') {
      visi[make_pair(at.first + 1, at.second)] = 1;
      q.push({make_pair(at.first + 1, at.second), d + 1});
    }
    if (at.second < w && !visi[make_pair(at.first, at.second + 1)] &&
        mat[at.first][at.second + 1] == '.') {
      visi[make_pair(at.first, at.second + 1)] = 1;
      q.push({make_pair(at.first, at.second + 1), d + 1});
    }
    if (at.first && !visi[make_pair(at.first - 1, at.second)] &&
        mat[at.first - 1][at.second] == '.') {
      visi[make_pair(at.first - 1, at.second)] = 1;
      q.push({make_pair(at.first - 1, at.second), d + 1});
    }
    if (at.second && !visi[make_pair(at.first, at.second - 1)] &&
        mat[at.first][at.second - 1] == '.') {
      visi[make_pair(at.first, at.second - 1)] = 1;
      q.push({make_pair(at.first, at.second - 1), d + 1});
    }
    q.pop();
  }
  return r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> mat[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (mat[i][j] == '.') {
        ans = max(bfs(make_pair(i, j)), ans);
        visi.clear();
      }
    }
  }
  cout << ans << endl;
  return 0;
}
