#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> s(h, vector<int>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char tmp;
      cin >> tmp;
      s[i][j] = (tmp == '.' ? 1 : 0);
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == 0) continue;
      int cnt = 0;
      vector<vector<int>> v = s;
      v[i][j] = 0;
      queue<pair<pair<int, int>, int>> q;
      q.push(make_pair(make_pair(i, j), 0));
      while (!q.empty()) {
        auto tmp = q.front();
        int x = tmp.first.first, y = tmp.first.second, z = tmp.second;
        q.pop();
        cnt = max(cnt, z);
        if (x > 0 && v[x - 1][y] == 1) {
          q.push(make_pair(make_pair(x - 1, y), z + 1));
          v[x - 1][y] = 0;
        }
        if (x < h - 1 && v[x + 1][y] == 1) {
          q.push(make_pair(make_pair(x + 1, y), z + 1));
          v[x + 1][y] = 0;
        }
        if (y > 0 && v[x][y - 1] == 1) {
          q.push(make_pair(make_pair(x, y - 1), z + 1));
          v[x][y - 1] = 0;
        }
        if (y > w - 1 && v[x][y + 1] == 1) {
          q.push(make_pair(make_pair(x, y + 1), z + 1));
          v[x][y + 1] = 0;
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}
