#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  int dist;
  node() {}
  node(int _y, int _x, int _d) : x(_x), y(_y), dist(_d) {}
};
int h, w;
char maze[(20 + 5)][(20 + 5)];
char vis[(20 + 5)][(20 + 5)];
int dirX[4] = {0, -1, 0, 1};
int dirY[4] = {1, 0, -1, 0};
int BFS(int x, int y) {
  queue<node> q;
  node t;
  memset(vis, 0, sizeof vis);
  node start(y, x, 0);
  vis[y][x] = 1;
  q.push(start);
  int res = -1;
  while (!q.empty()) {
    start = q.front();
    q.pop();
    res = max(res, start.dist);
    for (int i = 0; i < 4; i++) {
      t.y = start.y + dirY[i];
      t.x = start.x + dirX[i];
      t.dist = start.dist + 1;
      if (t.y >= 0 && t.y < w && t.x >= 0 && t.x < w && maze[t.y][t.x] == '.' &&
          vis[t.y][t.x] == 0) {
        vis[t.y][t.x] = 1;
        q.push(t);
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> maze[i];
  int res = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (maze[i][j] == '#') continue;
      res = max(res, BFS(i, j));
    }
  }
  cout << res << endl;
}
