#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1},
          dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int h, w;
char a[25][25];
inline bool in_range(int x, int y) {
  return x >= 0 && x < h && y >= 0 && y < w;
}
inline int bfs(int i, int j) {
  queue<pair<int, int> > q;
  q.push(make_pair(i, j));
  int d[25][25];
  bool was[25][25];
  for (int pair<int, int> = 0; pair<int, int> < 24; pair<int, int> ++)
    for (int jj = 0; jj < 24; jj++)
      d[pair<int, int>][jj] = -1, was[pair<int, int>][jj] = false;
  d[i][j] = 0;
  was[i][j] = true;
  while (int(q.size())) {
    int x = q.front().first;
    int y = q.front().second;
    for (int k = 0; k < 4; k++) {
      if (in_range(x + dx[k], y + dy[k]) && !was[x + dx[k]][y + dy[k]] &&
          a[x + dx[k]][y + dy[k]] == '.') {
        q.push({x + dx[k], y + dy[k]});
        was[x + dx[k]][y + dy[k]] = true;
        d[x + dx[k]][y + dy[k]] = d[x][y] + 1;
      }
    }
    q.pop();
  }
  int res = -1;
  for (int pair<int, int> = 0; pair<int, int> < 24; pair<int, int> ++)
    for (int jj = 0; jj < 24; jj++) res = max(res, d[pair<int, int>][jj]);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> a[i][j];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int res = bfs(i, j);
      ans = max(ans, res);
    }
  }
  cout << ans;
  return 0;
}
