#include <bits/stdc++.h>
using namespace std;
char k[30][30];
struct Node {
  int x, y;
};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int h, w, sum, mp[30][30];
void bfs(int x, int y) {
  sum = 0;
  queue<Node> q;
  Node b;
  q.push({x, y});
  while (!q.empty()) {
    b = q.front();
    q.pop();
    int flag = 0;
    for (int i = 0; i < 4; i++) {
      int xx = b.x + dx[i];
      int yy = b.y + dy[i];
      if (xx == x && yy == y) continue;
      if (xx >= 1 && xx <= h && yy >= 1 && yy <= w && k[xx][yy] == '.' &&
          !mp[xx][yy]) {
        q.push({xx, yy});
        sum = max(sum, mp[xx][yy]);
        mp[xx][yy] = mp[b.x][b.y] + 1;
      }
    }
  }
}
void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) cin >> k[i] + 1;
  int res = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (k[i][j] == '.') {
        memset(mp, 0, sizeof(mp));
        bfs(i, j);
        res = max(res, sum);
      }
    }
  }
  cout << res << endl;
}
int main() {
  header();
  solve();
  return 0;
}
