#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  char t[20][20];
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      cin >> t[i][j];
    }
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  int maxi = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      queue<pair<int, int> > que;
      vector<vector<int> > dist(h, vector<int>(w, -1));
      dist[i][j] = 0;
      que.emplace(i, j);
      while (que.size()) {
        int y, x;
        tie(y, x) = que.front();
        que.pop();
        for (int i = 0; i < (int)(4); i++) {
          int tx = x + dx[i];
          int ty = y + dy[i];
          if (!(0 <= tx && tx <= w - 1 && 0 <= ty && ty <= h - 1)) continue;
          if (t[ty][tx] == '#') continue;
          if (dist[ty][tx] != -1) continue;
          dist[ty][tx] = dist[y][x] + 1;
          maxi = max(maxi, dist[ty][tx]);
          que.emplace(ty, tx);
        }
      }
    }
  cout << maxi << endl;
  return 0;
}
