#include <bits/stdc++.h>
using namespace std;
inline void Input_Output() {}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
char a[33][33];
int u[33][33];
int get(int x, int y) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) u[i][j] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  u[x][y] = 1;
  while (q.size()) {
    auto it = q.front();
    q.pop();
    for (int di = 0; di < 4; di++) {
      int nx = it.first + dx[di], ny = it.second + dy[di];
      if (nx < 0 || ny < 0 || nx >= n || ny >= m || a[nx][ny] == '#') continue;
      if (!u[nx][ny]) {
        u[nx][ny] = u[it.first][it.second] + 1;
        q.push(make_pair(nx, ny));
      }
    }
  }
  int res = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) res = max(res, u[i][j]);
  return res - 1;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (a[i][j] != '#') {
        ans = max(ans, get(i, j));
      }
  }
  cout << ans << '\n';
  return 0;
}
