#include <bits/stdc++.h>
using namespace std;
char maze[21][21];
int max_step, step[21][21];
bool visit[21][21];
int dx[5] = {0, 1, -1, 0, 0};
int dy[5] = {0, 0, 0, 1, -1};
struct node {
  int x, y;
} note;
queue<node> q;
int main() {
  int x, y;
  scanf("%d%d", &x, &y);
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= y; j++) {
      memset(step, 0, sizeof(step));
      memset(visit, 0, sizeof(visit));
      if (maze[i][j] == '#') continue;
      q.push(node{i, j});
      while (!q.empty()) {
        node u = q.front();
        q.pop();
        int X = u.x;
        int Y = u.y;
        for (int k = 1; k <= 4; k++) {
          int xx = X + dx[k];
          int yy = Y + dy[k];
          if (maze[xx][yy] == '.' && !visit[xx][yy]) {
            q.push(node{xx, yy});
            step[xx][yy] = step[X][Y] + 1;
            max_step = max(max_step, step[xx][yy]);
            visit[xx][yy] = true;
          }
        }
      }
    }
  }
  printf("%d", max_step);
  return 0;
}
