#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
char maze[20][21];
int N, M;
int mx = 0;
int d[20][21];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void bfs(int sx, int sy) {
  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 (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;
        mx = max(mx, d[nx][ny]);
      }
    }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (M); j++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (M); j++) {
      bfs(i, j);
    }
  }
  cout << mx << endl;
  return 0;
}
