#include <bits/stdc++.h>
const long long MOD = 1000000007;
using namespace std;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (long long i = 0; i < (long long)h; ++i) cin >> v[i];
  int ans = 0;
  for (long long i = 0; i < (long long)h; ++i) {
    for (long long j = 0; j < (long long)w; ++j) {
      if (v[i][j] == '#') continue;
      queue<pair<int, int>> p;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      p.push({i, j});
      dist[i][j] = 0;
      while (!p.empty()) {
        pair<int, int> tmp = p.front();
        p.pop();
        for (long long k = 0; k < (long long)4; ++k) {
          int ny = tmp.first + dy[k];
          int nx = tmp.second + dx[k];
          if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
          if (v[ny][nx] == '.') {
            if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
            if (dist[ny][nx] >= dist[tmp.first][tmp.second] + 1 ||
                dist[ny][nx] == -1)
              dist[ny][nx] = dist[tmp.first][tmp.second] + 1,
              ans = max(ans, dist[ny][nx]), p.push({ny, nx});
          }
        }
      }
    }
  }
  cout << ans << endl;
}
