#include <bits/stdc++.h>
const int INF = 2147483647;
const long long int MOD = 1000000007;
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      queue<pair<pair<int, int>, int>> q;
      vector<vector<bool>> checked(h);
      for (int _i = 0; _i < h; _i++) {
        for (int _j = 0; _j < w; _j++) {
          checked[_i].push_back(false);
        }
      }
      q.push(make_pair(make_pair(i, j), 0));
      checked[i][j] = true;
      while (!q.empty()) {
        auto c = q.front();
        q.pop();
        ans = max(ans, c.second);
        int x = c.first.second;
        int y = c.first.first;
        checked[y][x] = true;
        if (x > 0 && s[y][x - 1] == '.' && !checked[y][x - 1]) {
          q.push(make_pair(make_pair(y, x - 1), c.second + 1));
        }
        if (x < w - 1 && s[y][x + 1] == '.' && !checked[y][x + 1]) {
          q.push(make_pair(make_pair(y, x + 1), c.second + 1));
        }
        if (y > 0 && s[y - 1][x] == '.' && !checked[y - 1][x]) {
          q.push(make_pair(make_pair(y - 1, x), c.second + 1));
        }
        if (y < h - 1 && s[y + 1][x] == '.' && !checked[y + 1][x]) {
          q.push(make_pair(make_pair(y + 1, x), c.second + 1));
        }
      }
    }
  }
  cout << ans << endl;
}
