#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> d(h + 2, vector<char>(w + 2, '#'));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> d[i][j];
  int ans = 0;
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      for (int k = 1; k <= h; k++) {
        for (int l = 1; l <= w; l++) {
          vector<vector<int>> a(h + 2, vector<int>(w + 2, -1));
          queue<pair<int, int>> q;
          if (d[i][j] == '#' || d[k][l] == '#') break;
          q.push({i, j});
          a[i][j] = 0;
          while (!q.empty()) {
            auto s = q.front();
            q.pop();
            for (int i = 0; i < 4; i++) {
              if (d[s.first + dy[i]][s.second + dx[i]] == '#') continue;
              if (a[s.first + dy[i]][s.second + dx[i]] != -1) continue;
              a[s.first + dy[i]][s.second + dx[i]] = a[s.first][s.second] + 1;
              q.push({s.first + dy[i], s.second + dx[i]});
            }
          }
          ans = max(ans, a[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
