#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};
  queue<pair<int, int>> q;
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        int c = dist[x][y];
        q.pop();
        for (int k = 0; k < 4; k++) {
          int kx = x+dx[k];
          int ky = y+dy[k];
          if (kx<0 || kx>=h || ky<0 || ky>=w) continue;
          if (dist[kx][ky] < 0 && s[kx][ky] == '.') {
            dist[kx][ky] = c+1;
            ans = max(ans, c+1);
            q.push(make_pair(kx, ky));
          }
        }
      }
    }
  }
  cout << ans << endl;
}