#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  char mat[n][m];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> mat[i][j];
  long long ans = 0, d = -1;
  long long R[] = {-1, 0, 1, 0};
  long long C[] = {0, 1, 0, -1};
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      d = 0;
      vector<vector<bool>> vis(n, vector<bool>(m, false));
      queue<pair<long long, long long>> q;
      queue<long long> dist;
      if (mat[i][j] == '.') {
        q.push({i, j});
        dist.push(d);
        vis[i][j] = true;
        while (!q.empty()) {
          long long x = q.front().first;
          long long y = q.front().second;
          d = dist.front();
          q.pop();
          dist.pop();
          bool check = false;
          for (long long k = 0; k < 4; k++) {
            long long a = x + R[k];
            long long b = y + C[k];
            if (a >= 0 and a < n and b >= 0 and b < m and mat[a][b] == '.' and
                !vis[a][b]) {
              if (!check) {
                check = true;
                d++;
              }
              q.push({a, b});
              dist.push(d);
              vis[a][b] = true;
            }
          }
        }
      }
    }
    ans = max(ans, d);
  }
  cout << ans << endl;
}
