#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
  return a = (a > b) ? b : a;
}
long long const INF = 1LL << 60;
long long const MOD = 1000000007;
long long const MAX_N = 100;
long long const MAX_M = 100;
char maze[MAX_N][MAX_M + 1];
long long H, W;
long long sx, sy;
long long gx, gy;
long long d[MAX_N][MAX_M];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs() {
  queue<pair<long long, long long> > que;
  for (long long i = 0; i < (H); i++)
    for (long long j = 0; j < (W); j++) d[i][j] = INF;
  que.push(pair<long long, long long>(sx, sy));
  d[sy][sx] = 0;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#' &&
          d[ny][nx] == INF) {
        que.push(pair<long long, long long>(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  return d[gy][gx];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  cin >> H >> W;
  for (long long i = 0; i < (H); i++)
    for (long long j = 0; j < (W); j++) {
      cin >> maze[i][j];
    }
  long long ans = 0;
  for (long long i = 0; i < (H); i++) {
    for (long long j = 0; j < (W); j++) {
      sx = j;
      sy = i;
      for (long long k = 0; k < (H); k++) {
        for (long long m = 0; m < (W); m++) {
          gy = k;
          gx = m;
          long long dist = bfs();
          chmax(ans, dist);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
