#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> maze.at(h).at(w);
    }
  }
  int ans = 0;
  for (int s_h = 0; s_h < H; s_h++) {
    for (int s_w = 0; s_w < W; s_w++) {
      queue<pair<int, int>> q;
      vector<vector<int>> min_num(H, vector<int>(W, INF));
      q.push(pair<int, int>(s_h, s_w));
      min_num[s_h][s_w] = 0;
      while (!q.empty()) {
        int now_x = q.front().first, now_y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
          int next_x = now_x + dx[i], next_y = now_y + dy[i];
          if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
          if (maze[next_x][next_y] == '#') continue;
          if (min_num[next_x][next_y] != INF) continue;
          min_num[next_x][next_y] = min_num[now_x][now_y] + 1;
          q.push(pair<int, int>(next_x, next_y));
        }
      }
      for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
          if (min_num[h][w] == INF) continue;
          ans = max(ans, min_num[h][w]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
