#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Int = long long;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
char grid[21][21];
int h, w;
int sx, sy;
int gx, gy;
int d[21][21];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int bfs() {
  queue<pair<int, int> > que;
  int res = 0;
  for (int(i) = 0; (i) < (int)(h); (i)++) {
    for (int(j) = 0; (j) < (int)(w); (j)++) {
      d[i][j] = -1;
    }
  }
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int(i) = 0; (i) < (int)(4); (i)++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && grid[nx][ny] != '#' &&
          d[nx][ny] == -1) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        res = max(res, d[nx][ny]);
      }
    }
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int(i) = 0; (i) < (int)(h); (i)++) {
    for (int(j) = 0; (j) < (int)(w); (j)++) {
      cin >> grid[i][j];
    }
  }
  int ans;
  int res;
  int max_ = 0;
  for (int(i) = 0; (i) < (int)(h); (i)++) {
    for (int(j) = 0; (j) < (int)(w); (j)++) {
      if (grid[i][j] == '#') break;
      sx = i;
      sy = j;
      ans = bfs();
      max_ = max(max_, ans);
    }
  }
  cout << max_;
  return 0;
}
