#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const int INF = 1e9 + 10;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
  int H, W; cin >> H >> W;
  vector<vector<bool>> maze(H + 2, vector<bool>(W + 2, false));
  rep(i, H) rep(j, W) {
    char S; cin >> S;
    if (S == '.') maze[i + 1][j + 1] = true;
  }

  auto bfs = [&](int sh, int sw) {
    vector<vector<int>> d(H + 2, vector<int>(W + 2, INF));
    d[sh][sw] = 0;
    queue<pair<int, int>> q;
    q.emplace(sh, sw);
    int res;
    while (!q.empty()) {
      int h, w;
      tie(h, w) = q.front(); q.pop();
      rep(k, 4) {
        int nh = h + dx[k], nw = w + dy[k];
        if (maze[nh][nw] && d[nh][nw] == INF) {
          q.emplace(nh, nw);
          res = d[nh][nw] = d[h][w] + 1;
        }
      }
    }
    return res;
  };

  int ans = 0;
  rep(i, H + 1) rep(j, W + 1) {
    if (maze[i][j]) ans = max(ans, bfs(i, j));
  }

  cout << ans << endl;
}
