#include <bits/stdc++.h>
using namespace std;
int INF = 99;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int N, M;
string maze[100];
int sx, sy, gx, gy;
int d[100][100];
bool isOK(int x, int y, int N, int M) {
  return (0 <= x and x < N and 0 <= y and y < M);
}
int 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], ny = p.second + dy[i];
      if (isOK(nx, ny, N, M) and maze[nx][ny] != '#' and d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  if (sx == 0 && sy == 0) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (d[i][j] != INF && ret <= d[i][j]) {
        ret = d[i][j];
      }
    }
  }
  return ret;
}
int main() {
  cin >> N >> M;
  for (string &s : maze) cin >> s;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      sx = i, sy = j;
      int tmp = bfs();
      if (ans < tmp) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
