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