#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
string vs[50];
int r, c, ans;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool ok(int i, int j) {
  return i >= 0 && i < r && j >= 0 && j < c && vs[i][j] == '.';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> r >> c;
  for (int i = 0; i < r; ++i) cin >> vs[i];
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      queue<pair<int, int>> q;
      vector<vector<int>> dist(r, vector<int>(c, INF));
      dist[i][j] = 0;
      q.push({i, j});
      while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int k = 0; k < 4; ++k) {
          if (ok(x + dx[k], y + dy[k]) &&
              dist[x][y] + 1 < dist[x + dx[k]][y + dy[k]]) {
            q.push({x + dx[k], y + dy[k]});
            dist[x + dx[k]][y + dy[k]] = dist[x][y] + 1;
            ans = max(ans, dist[x][y] + 1);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
