#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> maze;
int path[22][22];
const int INF = 40000;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
void bfs(int s1, int s2) {
  for (int i = 0; i < (22); ++i)
    for (int j = 0; j < (22); ++j) path[i][j] = INF;
  path[s1][s2] = 0;
  queue<pair<int, int> > q1;
  q1.push(make_pair(s1, s2));
  while (!q1.empty()) {
    pair<int, int> v = q1.front();
    q1.pop();
    int x = v.first;
    int y = v.second;
    for (int i = 0; i < (4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx > H - 1 || ny < 0 || ny > W - 1) continue;
      if (path[nx][ny] < path[x][y] + 1 || maze[nx][ny] == '#') continue;
      path[nx][ny] = path[x][y] + 1;
      q1.push(make_pair(nx, ny));
    }
  }
}
int main() {
  cin >> H >> W;
  string tmp;
  for (int i = 0; i < (H); ++i) {
    cin >> tmp;
    maze.push_back(tmp);
  }
  int ans = 0;
  for (int s1 = 0; s1 < H; ++s1) {
    for (int s2 = 0; s2 < W; ++s2) {
      if (maze[s1][s2] == '.') {
        bfs(s1, s2);
        for (int e1 = 0; e1 < H; ++e1) {
          for (int e2 = 0; e2 < W; ++e2) {
            if (maze[e1][e2] != '#') ans = max(ans, path[e1][e2]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
