#include <bits/stdc++.h>
using namespace std;
int INF = (1LL << 30) - 1;
int MOD = 1e9 + 7;
vector<string> table(21);
int H, W;
int calc(int sy, int sx, int gy, int gx) {
  queue<pair<int, int> > que;
  vector<vector<int> > dist(H, vector<int>(W, INF));
  dist[sy][sx] = 0;
  que.push(pair<int, int>(sy, sx));
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int dx[] = {1, -1, 0, 0};
    int dy[] = {0, 0, 1, -1};
    for (int i = int(0); i < int(4); ++i) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (table[ny][nx] == '#') continue;
      if (dist[ny][nx] != INF) continue;
      if (dist[ny][nx] > dist[p.first][p.second]) {
        dist[ny][nx] = dist[p.first][p.second] + 1;
        que.push(pair<int, int>(ny, nx));
      }
    }
  }
  if (dist[gy][gx] == INF)
    return -1;
  else
    return dist[gy][gx];
}
int main() {
  cin >> H >> W;
  for (int i = int(0); i < int(H); ++i) cin >> table[i];
  int maxi = 0;
  for (int i = int(0); i < int(H); ++i)
    for (int j = int(0); j < int(W); ++j)
      for (int k = int(0); k < int(H); ++k)
        for (int l = int(0); l < int(W); ++l) {
          maxi = max(maxi, calc(i, j, k, l));
        }
  cout << maxi << endl;
}
