#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
vector<long long> xa = {0, -1, 1, 0};
vector<long long> ya = {1, 0, 0, -1};
long long h, w;
vector<vector<char>> s;
vector<vector<bool>> vis;
void dfs(long long x, long long y) {
  queue<pair<long long, pair<long long, long long>>> q;
  q.push({0, {x, y}});
  while (!q.empty()) {
    vis[x][y] = true;
    x = q.front().second.first;
    y = q.front().second.second;
    long long dist = q.front().first;
    q.pop();
    for (long long i = 0; i < 4; ++i) {
      long long nx = x + xa[i];
      long long ny = y + ya[i];
      if ((nx < h) && (ny < w) && (nx >= 0 && ny >= 0) && (!vis[nx][ny]) &&
          (s[nx][ny] != '#')) {
        q.push({dist + 1, {nx, ny}});
        ans = max(ans, dist + 1);
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> h >> w;
  s.resize(h, vector<char>(w));
  for (long long i = 0; i < (h); ++i) {
    for (long long j = 0; j < (w); ++j) {
      cin >> s[i][j];
    }
  }
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < h; ++j) {
      if (s[i][j] == '#') continue;
      vis.clear();
      vis.resize(h, vector<bool>(w));
      dfs(i, j);
    }
  }
  cout << ans;
}
