#include <bits/stdc++.h>
using namespace std;
static const int INF = 1e9;
static const int MOD = 1000000007;
int H, W;
char s[50][50];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int solve(int sx, int sy) {
  int d[50][50] = {};
  int used[50][50] = {};
  queue<pair<int, int> > que;
  que.push({sx, sy});
  used[sx][sy] = 1;
  while (!que.empty()) {
    pair<int, int> q = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = q.first + dx[i];
      int ny = q.second + dy[i];
      if (used[nx][ny] == 1) continue;
      if (nx >= H || ny >= W || nx < 0 || ny < 0 || s[nx][ny] == '#') continue;
      used[nx][ny] = 1;
      d[nx][ny] = d[q.first][q.second] + 1;
      que.push({nx, ny});
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, d[i][j]);
    }
  }
  return ans;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans << endl;
}
