#include <bits/stdc++.h>
using namespace std;
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 < w; i++) {
    for (int j = 0; j < h; j++) {
      int sx = i;
      int sy = j;
      if (grid[sy][sx] == '.') {
        queue<pair<int, pair<int, int>>> que;
        vector<vector<int>> dist(h, vector<int>(w, -1));
        que.push(make_pair(0, make_pair(sy, sx)));
        dist[sy][sx] = 0;
        while (que.size()) {
          pair<int, pair<int, int>> now = que.front();
          que.pop();
          int d = now.first;
          int now_y = now.second.first;
          int now_x = now.second.second;
          dist[now_y][now_x] = d;
          ans = max(ans, d);
          int dy[4] = {0, 1, 0, -1};
          int dx[4] = {1, 0, -1, 0};
          for (int i = 0; i < 4; i++) {
            int ny = now_y + dy[i];
            int nx = now_x + dx[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && dist[ny][nx] == -1 &&
                grid[ny][nx] == '.') {
              que.push(make_pair(d + 1, make_pair(ny, nx)));
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
