#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); i++) {
    cin >> S[i];
  }
  int ans = 0;
  for (int si = 0; si < (int)(H); si++) {
    for (int sj = 0; sj < (int)(W); sj++) {
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      dist[si][sj] = 0;
      que.push(make_pair(si, sj));
      while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        int di[4] = {0, 1, -1, 0};
        int dj[4] = {-1, 0, 0, 1};
        for (int k = 0; k < (int)(4); k++) {
          int ni = v.first + di[k];
          int nj = v.second + dj[k];
          if ((ni < 0 || H <= ni) || (nj < 0 || W <= nj)) {
            continue;
          }
          if (S[ni][nj] == '.' && dist[ni][nj] == -1) {
            dist[ni][nj] = dist[v.first][v.second] + 1;
            que.push(make_pair(ni, nj));
          }
        }
      }
      for (int gi = 0; gi < (int)(H); gi++) {
        for (int gj = 0; gj < (int)(W); gj++) {
          ans = max(ans, dist[gi][gj]);
        }
      }
    }
  }
  cout << ans << endl;
}
