#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, check;
  cin >> H >> W;
  char tmp;
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  vector<vector<int>> maze(H + 2, vector<int>(W + 2, 0));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> tmp;
      if (tmp == '.') {
        maze[i + 1][j + 1] = 1;
      }
    }
  }
  vector<vector<int>> table(H + 2, vector<int>(W + 2, -1));
  queue<pair<int, int>> que;
  int ans = 0;
  for (int i = 1; i < H + 1; ++i) {
    for (int j = 1; j < W + 1; ++j) {
      for (int k = 0; k < H + 2; ++k) {
        for (int l = 0; l < W + 2; ++l) {
          table[k][l] = -1;
        }
      }
      table[i][j] = 0;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<int, int> tmp_pair = que.front();
        que.pop();
        int tmp_x = tmp_pair.first, tmp_y = tmp_pair.second;
        int dist = table[tmp_x][tmp_y] + 1;
        for (int d = 0; d < 4; ++d) {
          int x = tmp_x + dx[d], y = tmp_y + dy[d];
          if (maze[x][y] == 1 && table[x][y] == -1) {
            table[x][y] = dist;
            que.push(make_pair(x, y));
            if (ans < dist) {
              ans = dist;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
