#include <bits/stdc++.h>
using namespace std;
const long double PI = (acos(-1));
vector<int> mx = {0, 0, 1, -1}, my = {1, -1, 0, 0};
int h, w;
vector<vector<char> > G;
vector<vector<bool> > U;
int solve(int x, int y) {
  int nx, ny, res = 0;
  queue<pair<pair<int, int>, int> > que;
  que.push(make_pair(pair<int, int>(x, y), 0));
  vector<vector<bool> > U(h, vector<bool>(w, false));
  while (!que.empty()) {
    pair<int, int> u = que.front().first;
    int d = que.front().second;
    que.pop();
    res = max(res, d);
    for (int i = 0; i < (int)(4); i++) {
      nx = u.first + mx[i];
      ny = u.second + my[i];
      if (nx < 0 || nx > h - 1 || ny < 0 || ny > w - 1) continue;
      if (G[nx][ny] == '#' || U[nx][ny]) continue;
      U[nx][ny] = true;
      que.push(make_pair(pair<int, int>(nx, ny), d + 1));
    }
  }
  return res;
}
int main() {
  int ans = 0;
  scanf("%d", &h), scanf("%d", &w);
  G.resize(h);
  for (int i = 0; i < (int)(h); i++) G[i].resize(w);
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) cin >> G[i][j];
  }
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (G[i][j] == '.') ans = max(ans, solve(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
