#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int h, w;
  cin >> h >> w;
  vector<string> v;
  v.push_back("######################");
  for (long long int i = 0; i < h; i++) {
    string in;
    cin >> in;
    v.push_back("#" + in + "#");
  }
  v.push_back("######################");
  long long int ans = 0;
  for (long long int sy = 1; sy <= h; sy++) {
    for (long long int sx = 1; sx <= w; sx++) {
      bool f[22][22] = {};
      queue<pair<long long int, pair<long long int, long long int> > > q;
      q.push(make_pair(0, make_pair(sy, sx)));
      while (q.size() > 0) {
        long long int k = q.front().first;
        long long int y = q.front().second.first;
        long long int x = q.front().second.second;
        q.pop();
        if (f[y][x]) continue;
        f[y][x] = true;
        ans = max(ans, k);
        if (v[y - 1][x] == '.') q.push(make_pair(k + 1, make_pair(sy - 1, sx)));
        if (v[y + 1][x] == '.') q.push(make_pair(k + 1, make_pair(sy + 1, sx)));
        if (v[y][x - 1] == '.') q.push(make_pair(k + 1, make_pair(sy, sx - 1)));
        if (v[y][x + 1] == '.') q.push(make_pair(k + 1, make_pair(sy, sx + 1)));
      }
    }
  }
  cout << ans << endl;
}
