#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
int H, W;
char board[20][20];
int dist[20][20];
int bfs(int sx, int sy, int gx, int gy) {
  for (long long i = 0; i < (int)(20); i++)
    memset(dist[i], -1, sizeof(dist[i]));
  dist[sy][sx] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    int nx, ny;
    for (long long i = 0; i < (int)(4); i++) {
      nx = dx[i] + p.first;
      ny = dy[i] + p.second;
      if (nx >= W || nx < 0 || ny >= H || ny < 0 || dist[ny][nx] != -1 ||
          board[ny][nx] == '#')
        continue;
      dist[ny][nx] = dist[p.second][p.first] + 1;
      que.push(make_pair(nx, ny));
    }
  }
  return dist[gx][gy];
}
int main() {
  cin >> H >> W;
  for (long long i = 0; i < (int)(H); i++) {
    for (long long j = 0; j < (int)(W); j++) {
      cin >> board[i][j];
    }
  }
  int ans = -1;
  for (long long i = 0; i < (int)(H); i++) {
    for (long long j = 0; j < (int)(W); j++) {
      if (board[i][j] == '#') continue;
      for (long long k = 0; k < (int)(H); k++) {
        for (long long l = 0; l < (int)(W); l++) {
          if (board[k][l] == '#') continue;
          int tmp = bfs(i, j, k, l);
          ans = max(tmp, ans);
        }
      }
    }
  }
  cout << ans << endl;
}
