#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int h, w, i, j, maxi = 0;
  cin >> h >> w;
  vector<string> m(h);
  for (int i = 0; i < h; i++) {
    cin >> m[i];
  }
  for (i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[i][j] = 0;
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<int, int> cur = que.front();
        int x = cur.first;
        int y = cur.second;
        que.pop();
        maxi = max(maxi, dist[x][y]);
        for (int dir = 0; dir < 4; dir++) {
          int next_x = x + dx[dir];
          int next_y = y + dy[dir];
          if (next_x >= h || next_x < 0 || next_y >= w || next_y < 0) continue;
          if (m[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;
          }
        }
      }
    }
  }
  cout << maxi << endl;
}
