#include <bits/stdc++.h>
using namespace std;
bool m[21][21];
int a[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') m[i][j] = true;
    }
  }
  int bmax = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!m[i][j]) continue;
      int dist[h][w];
      fill((int*)dist, (int*)(dist + h), -1);
      dist[i][j] = 0;
      queue<pair<int, int> > que;
      que.push(pair<int, int>(i, j));
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int dx = a[k][0], dy = a[k][1];
          if (dist[p.first + dx][p.second + dy] < 0 &&
              m[p.first + dx][p.second + dy]) {
            dist[p.first + dx][p.second + dy] = dist[p.first][p.second] + 1;
            que.push(pair<int, int>(p.first + dx, p.second + dy));
            bmax = max(bmax, dist[p.first + dx][p.second + dy]);
          }
        }
      }
    }
  }
  cout << bmax << endl;
  return 0;
}
