#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
using ii = pair<int, int>;
int H, W;
vector<string> S(20);
vector<vector<int> > D(21, vector<int>(21, INF));
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int bfs(int y, int x) {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      D[i][j] = INF;
    }
  }
  D[y][x] = 0;
  queue<ii> que;
  que.push(make_pair(y, x));
  int res = 0;
  while (!que.empty()) {
    ii p = que.front();
    que.pop();
    res = max(res, D[p.first][p.second]);
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (S[ny][nx] != '#' && ny >= 0 && ny < H && nx >= 0 && nx < W &&
          D[ny][nx] == INF) {
        D[ny][nx] = D[p.first][p.second] + 1;
        que.push(make_pair(ny, nx));
      }
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int m = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        m = max(m, bfs(i, j));
      }
    }
  }
  cout << m << endl;
  return 0;
}
