#include <bits/stdc++.h>
using namespace std;
char S[25][25];
bool visited[25][25];
int H, W;
int mx = 0;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
struct node {
  int x, y, t;
  node(int x_, int y_, int t_) {
    x = x_;
    y = y_;
    t = t_;
  }
};
void dfs(int x, int y) {
  memset(visited, false, sizeof(visited));
  queue<node> q;
  node n = node(x, y, 0);
  q.push(n);
  visited[x][y] = true;
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int x2 = now.x + dir[i][0];
      int y2 = now.y + dir[i][1];
      if (0 <= x2 && x2 < H && 0 <= y2 && y2 < W && !visited[x2][y2] &&
          S[x2][y2] != '#') {
        node next = node(x2, y2, now.t + 1);
        q.push(next);
        visited[x2][y2] = true;
        mx = max(mx, now.t + 1);
      }
    }
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        continue;
      }
      dfs(i, j);
    }
  }
  cout << mx << endl;
  return 0;
}
