#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> M(H, vector<char>(W));
  bool no_check = true;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      cin >> M[i][j];
      if (M[i][j] == '#') no_check = false;
    }
  }
  queue<pair<int, pair<int, int>>> que;
  vector<pair<int, int>> dir(4);
  dir[0] = {+1, 0};
  dir[1] = {-1, 0};
  dir[2] = {0, +1};
  dir[3] = {0, -1};
  int ans = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      if (M[i][j] == '#') continue;
      int step = 0;
      que.push({0, {i, j}});
      vector<vector<bool>> visit(H, vector<bool>(W, false));
      while (!que.empty()) {
        auto t = que.front();
        que.pop();
        visit[t.second.first][t.second.second] = true;
        step = max(step, t.first);
        for (auto d : dir) {
          int ny = t.second.first + d.first;
          int nx = t.second.second + d.second;
          if (nx < 0 || ny < 0 || H <= ny || W <= nx) continue;
          if (visit[ny][nx] == true) continue;
          if (M[ny][nx] == '#') continue;
          que.push({t.first + 1, {ny, nx}});
        }
      }
      ans = max(ans, step);
      if (no_check) break;
    }
  }
  cout << ans << endl;
  return 0;
}
