#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
vector<string> field;
int dist[21][21];
int H, W;
int ans = -1;
void bfs(int sx, int sy) {
  memset(dist, -1, sizeof(dist));
  dist[sx][sy] = 0;
  queue<pair<int, int> > que;
  que.push(make_pair(sx, sy));
  while (!que.empty()) {
    pair<int, int> P = que.front();
    que.pop();
    int xx = P.first;
    int yy = P.second;
    for (int i = 0; i < 4; i++) {
      int nx = xx + dx[i];
      int ny = yy + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (field[nx][ny] == '#') continue;
      if (dist[nx][ny] == -1 || dist[nx][ny] > dist[xx][yy] + 1) {
        dist[nx][ny] = dist[xx][yy] + 1;
        que.push(make_pair(nx, ny));
      }
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        ans = max(ans, dist[i][j]);
      }
    }
  }
}
int main() {
  cin >> H >> W;
  field.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bfs(i, j);
    }
  }
  cout << ans << endl;
}
