#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> data(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> data[i][j];
  priority_queue<long long> py;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      queue<long long> que;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      que.push(i);
      que.push(j);
      dist[i][j] = 0;
      while (que.empty() != 1) {
        int a = que.front();
        que.pop();
        int b = que.front();
        if (a + 1 < h && dist[a + 1][b] == -1 && data[a + 1][b] != '#') {
          que.push(a + 1);
          que.push(b);
          dist[a + 1][b] = 1 + dist[a][b];
        }
        if (a - 1 > -1 && dist[a - 1][b] == -1 && data[a - 1][b] != '#') {
          que.push(a - 1);
          que.push(b);
          dist[a - 1][b] = 1 + dist[a][b];
        }
        if (b + 1 < w && dist[a][b + 1] == -1 && data[a][b + 1] != '#') {
          que.push(a);
          que.push(b + 1);
          dist[a][b + 1] = 1 + dist[a][b];
        }
        if (b - 1 > -1 && dist[a][b - 1] == -1 && data[a][b - 1] != '#') {
          que.push(a);
          que.push(b - 1);
          dist[a][b - 1] = 1 + dist[a][b];
        }
        que.pop();
      }
      for (int p = 0; p < h; p++) {
        for (int q = 0; q < w; q++) {
          py.push(dist[p][q]);
        }
      }
    }
  }
  cout << py.top();
}
