#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};
int maxStep = 0;
map<pair<int, int>, int> dist;
void bfs(int i, int j) {
  map<pair<int, int>, bool> visited;
  queue<pair<int, int>> q;
  q.push({i, j});
  visited[{i, j}] = true;
  dist[{i, j}] = 0;
  while (!q.empty()) {
    int h = q.front().first;
    int v = q.front().second;
    visited[{h, v}] = true;
    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;
          maxStep = max(dist[{x, y}], maxStep);
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> maze[i][j];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] != '.') continue;
      bfs(i, j);
      dist.clear();
    }
  }
  cout << maxStep << endl;
  return 0;
}
