#include <bits/stdc++.h>
using namespace std;
int H, W;
char S[20][20];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
struct ichi {
  int y;
  int x;
  int depth;
};
queue<ichi> q;
int res = 0;
int bfs(int s, int t, int h) {
  int hantei[20][20] = {};
  struct ichi start;
  start.x = t;
  start.y = s;
  start.depth = h;
  q.push(start);
  while (!q.empty()) {
    ichi now = q.front();
    q.pop();
    hantei[now.y][now.x] = 1;
    res = max(res, now.depth);
    for (int i = 0; i < 4; i++) {
      ichi next = {now.y + dy[i], now.x + dx[i], now.depth + 1};
      if (next.x < 0 || next.y >= H || next.y < 0 || next.x >= W) continue;
      if (S[next.y][next.x] == '#') continue;
      if (hantei[next.y][next.x] == 1) continue;
      if (next.y >= 0 && next.y < H && next.x >= 0 && next.x < W &&
          S[next.y][next.y] == '.') {
        q.push(next);
      }
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int ans = 0;
  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      if (S[a][b] == '#') continue;
      ans = max(ans, bfs(a, b, 0));
    }
  }
  cout << ans;
  return 0;
}
