#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpi = vector<pi>;
using vpll = vector<ll>;
using vpld = vector<ld>;
using vti3 = vector<ti3>;
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int bfs(int i, int j, char S[21][21], int H, int W) {
  int dist[21][21];
  memset(dist, -1, 21 * 21 * sizeof(int));
  dist[i][j] = 0;
  std::queue<pi> que;
  que.push(make_pair(i, j));
  int ret = 0;
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int i = p.first;
    int j = p.second;
    for (int k = 0; k < int(4); ++k) {
      int x = i + dx[k];
      int y = j + dy[k];
      if (0 <= x && x < H && 0 <= y && y < W && S[x][y] != '#' &&
          dist[x][y] == -1) {
        int t = dist[i][j] + 1;
        dist[x][y] = t;
        if (t > ret) ret = t;
        que.push(make_pair(x, y));
      }
    }
  }
  return ret;
}
void solve() {
  int H, W;
  cin >> H >> W;
  char S[21][21];
  for (int i = 0; i < int(H); ++i)
    for (int j = 0; j < int(W); ++j) cin >> S[i][j];
  int max = 0;
  for (int i = 0; i < int(H); ++i) {
    for (int j = 0; j < int(W); ++j) {
      int d = bfs(i, j, S, H, W);
      if (d > max) max = d;
    }
  }
  cout << max << endl;
}
int main() {
  cin.tie(NULL);
  solve();
  return 0;
}
