#include <bits/stdc++.h>
using namespace std;
int nx[5] = {-1, 0, 1, 0};
int ny[5] = {0, -1, 0, 1};
int main() {
  int h, w, mx = 0;
  int dist[29][29];
  queue<pair<int, int> > q;
  string s[29];
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int gi = 0; gi < h; gi++) {
    for (int gj = 0; gj < w; gj++) {
      memset(dist, -1, sizeof(dist));
      while (!q.empty()) q.pop();
      q.push(pair<int, int>(gi, gj));
      dist[gi][gj] = 0;
      while (!q.empty()) {
        int nx_x, nx_y;
        int fr_y = q.front().first;
        int fr_x = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
          nx_x = fr_x + nx[i];
          nx_y = fr_y + ny[i];
          if (0 <= nx_x && nx_x <= w - 1 && 0 <= nx_y && nx_y <= h - 1 &&
              dist[nx_y][nx_x] == -1 && s[nx_y][nx_x] == '.') {
            dist[nx_y][nx_x] = dist[fr_y][fr_x] + 1;
            q.push(pair<int, int>(nx_y, nx_x));
          }
        }
      }
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (s[i][j] == '.') mx = max(mx, dist[i][j]);
        }
      }
    }
  }
  cout << mx << endl;
}
