#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
int H, W, h, w, nh, nw;
vector<pair<int, int>> way = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int bfs(int sh, int sw, int gh, int gw, vector<string> &maze) {
  vector<vector<int>> visited(H, vector<int>(W, -1));
  visited[sh][sw] = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(sh, sw));
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    h = p.first;
    w = p.second;
    for (auto wp : way) {
      nh = h + wp.first;
      nw = w + wp.second;
      if (nh == gh && nw == gw) return visited[h][w] + 1;
      if (nh < 0 || nh > H - 1 || nw < 0 || nw > W - 1) continue;
      if (maze[nh][nw] == '#') continue;
      if (visited[nh][nw] != -1) continue;
      visited[nh][nw] = visited[h][w] + 1;
      q.push(make_pair(nh, nw));
    }
  }
}
int main() {
  cin >> H >> W;
  vector<string> maze(H);
  for (int i = 0; i < H; i++) cin >> maze[i];
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if (i == k && j == l) continue;
          if (maze[i][j] == '#' || maze[k][l] == '#') continue;
          ans = max(ans, bfs(i, j, k, l, maze));
        }
      }
    }
  }
  cout << ans << "\n";
}
