#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char g[25][25];
int n, m;
bool vis[25][25];
int ps[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
struct Node {
  int x, y, d;
};
int BFS(int x, int y) {
  queue<Node> que;
  Node t;
  t.x = x, t.y = y, t.d = 0;
  que.push(t);
  Node tmp;
  vis[x][y] = true;
  int ans = 0;
  memset(vis, false, sizeof(vis));
  while (!que.empty()) {
    tmp = que.front();
    que.pop();
    for (int i = 0; i < 4; ++i) {
      int dx = tmp.x + ps[i][0];
      int dy = tmp.y + ps[i][1];
      if (dx >= 0 && dx < n && dy >= 0 && dy < m && vis[dx][dy] == false &&
          g[dx][dy] == '.') {
        t.x = dx, t.y = dy, t.d = tmp.d + 1;
        que.push(t);
        vis[dx][dy] = true;
        ans = max(ans, tmp.d + 1);
      }
    }
  }
  return ans;
}
int main() {
  int ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> g[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (g[i][j] == '.') ans = max(ans, BFS(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
