#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
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;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        priority_queue<pair<int, pair<int, int>>,
                       std::vector<pair<int, pair<int, int>>>,
                       std::greater<pair<int, pair<int, int>>>>
            pq;
        pq.push(make_pair(0, make_pair(j, i)));
        vector<vector<int>> t(h, vector<int>(w));
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) t[k][l] = -1;
        }
        while (!pq.empty()) {
          pair<int, pair<int, int>> p = pq.top();
          pq.pop();
          int c = p.first;
          int x = p.second.first;
          int y = p.second.second;
          for (int k = 0; k < 4; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (nx >= 0 && nx < w && ny >= 0 && ny < h && s[ny][nx] == '.') {
              if (t[ny][nx] > c + 1 || t[ny][nx] == -1) {
                t[ny][nx] = c + 1;
                pq.push(make_pair(c + 1, make_pair(nx, ny)));
              }
            }
          }
        }
        int tans = 0;
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) tans = max(tans, t[k][l]);
        }
        ans = max(ans, tans);
      }
    }
  }
  cout << ans << endl;
}
