#include <bits/stdc++.h>
using namespace std;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
const double pi = acos(-1.0);
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> g(H, vector<char>(W));
  for (long long i = 0; i < H; i++)
    for (long long j = 0; j < W; j++) cin >> g[i][j];
  int ans = 0;
  for (long long i = 0; i < H; i++)
    for (long long j = 0; j < W; j++) {
      vector<vector<int>> seen(H, vector<int>(W, -1));
      seen[i][j] = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(i, j));
      while (q.size()) {
        auto now = q.front();
        q.pop();
        for (long long k = 0; k < 4; k++) {
          int nx = now.first + dx[k];
          int ny = now.second + dy[k];
          if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
          if (g[nx][ny] == '#') continue;
          if (seen[nx][ny] != -1) continue;
          seen[nx][ny] = seen[now.first][now.second] + 1;
          q.push(make_pair(nx, ny));
        }
      }
      int can = 0;
      for (long long k = 0; k < H; k++)
        for (long long l = 0; l < W; l++) chmax(can, seen[k][l]);
      chmax(ans, can);
    }
  cout << ans << endl;
}
