#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  for (int i = 0; i < (H); i++) cin >> maze[i];
  int mx = 0;
  for (int k = 0; k < (H); k++) {
    for (int l = 0; l < (W); l++) {
      vector<vector<int> > dist(H, vector<int>(W, -1));
      dist[k][l] = 0;
      queue<pair<int, int> > que;
      que.push(make_pair(k, l));
      while (!que.empty()) {
        pair<int, int> current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();
        for (int d = 0; d < (4); d++) {
          int next_x = x + dx[d];
          int next_y = y + dy[d];
          if (next_x < 0 || next_x >= H) continue;
          if (next_y < 0 || next_y >= W) continue;
          if (maze[next_x][next_y] == '#') continue;
          if (dist[next_x][next_y] == -1) {
            que.push(make_pair(next_x, next_y));
            dist[next_x][next_y] = dist[x][y] + 1;
          }
        }
      }
      for (int i = 0; i < (H); i++) {
        for (int j = 0; j < (W); j++) {
          mx = max(mx, dist[i][j]);
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
