#include <bits/stdc++.h>
using namespace std;
int h, w;
bool valid(int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; }
char maze[21][21]{};
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
map<pair<int, int>, int> dist;
map<pair<int, int>, bool> visited;
map<pair<pair<int, int>, pair<int, int>>, bool> processed;
int goalI, goalJ = 0;
int cnt = 0;
int MAX = (int)900;
int bfs(int i, int j) {
  queue<pair<int, int>> q;
  q.push({i, j});
  visited[{i, j}] = true;
  dist[{i, j}] = 0;
  map<pair<int, int>, pair<int, int>> processed;
  while (!q.empty()) {
    cnt++;
    if (cnt >= MAX) {
      return -MAX;
    }
    int h = q.front().first;
    int v = q.front().second;
    visited[{h, v}] = true;
    if (h == goalI && v == goalJ) break;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int x = h + dx[k];
      int y = v + dy[k];
      if (valid(x, y)) {
        if (maze[x][y] == '.' && visited.count({x, y}) == 0) {
          q.push({x, y});
          dist[{x, y}] = dist[{h, v}] + 1;
        }
      }
    }
  }
  return dist[{goalI, goalJ}];
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> maze[i][j];
  int maxStep = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] != '.') continue;
      for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (maze[x][y] != '.') continue;
          if (i == x && j == y) continue;
          if (processed[{{i, j}, {x, y}}] == 1) continue;
          if (processed[{{x, y}, {i, j}}] == 1) continue;
          visited.clear();
          dist.clear();
          goalI = x;
          goalJ = y;
          cnt = 0;
          maxStep = max(maxStep, bfs(i, j));
          processed[{{i, j}, {x, y}}] = 1;
        }
      }
    }
  }
  cout << maxStep << endl;
  return 0;
}
