#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; ++i) {
    cin >> grid[i];
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      queue<pair<int, int>> q;
      vector<vector<int>> dist(h, vector<int>(w, 1001001001));
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (int k = 0; k < 4; ++k) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
          if (grid[nx][ny] == '#') continue;
          if (dist[nx][ny] != 1001001001) continue;
          dist[nx][ny] = dist[x][y] + 1;
          q.push(make_pair(nx, ny));
        }
      }
      for (int l = 0; l < h; ++l) {
        for (int k = 0; k < w; ++k) {
          if (dist[l][k] != 1001001001) ans = max(ans, dist[l][k]);
        }
      }
    }
  }
  cout << ans << endl;
}
