#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
const int MAX_N = 20;
const int MAX_M = 20;
char maze[MAX_N][MAX_M + 1];
int N, M;
int sx, sy;
int gx, gy;
int d[MAX_N][MAX_M];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs() {
  queue<pair<int, int> > que;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> maze[i][j];
    }
  }
  int maxd[MAX_N][MAX_M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (maze[i][j] != '#') {
        int max = 0;
        sx = i;
        sy = j;
        bfs();
        for (int k = 0; k < N; k++) {
          for (int m = 0; m < M; m++) {
            if (max < d[k][m] && d[k][m] != INF) {
              max = d[k][m];
            }
          }
        }
      }
    }
  }
  int answer = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (answer < maxd[i][j]) {
        answer = maxd[i][j];
      }
    }
  }
  cout << answer << endl;
}
