#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, map<int, int>> maxx;
char mat[25][25];
map<pair<int, int>, bool> visited;
map<pair<int, int>, int> levels;
int xd[4] = {-1, 1, 0, 0};
int yd[4] = {0, 0, -1, 1};
void getmax(int xx, int yy) {
  queue<pair<int, int>> q;
  q.push({xx, yy});
  maxx[xx][yy] = 0;
  visited[{xx, yy}] = true;
  while (q.size()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < 4; i++) {
      int xnow = x + xd[i];
      int ynow = y + yd[i];
      if ((xnow >= n) || (xnow < 0) || (ynow >= m) || (ynow < 0) ||
          (mat[xnow][ynow] == '#') || (visited[{xnow, ynow}]))
        continue;
      visited[{xnow, ynow}] = true;
      maxx[xnow][ynow] = maxx[x][y] + 1;
      q.push({xnow, ynow});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      maxx.clear();
      visited.clear();
      getmax(i, j);
      for (int h = 0; h < n; h++) {
        for (int g = 0; g < m; g++) {
          ans = max(ans, maxx[h][g]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
