#include <bits/stdc++.h>
using namespace std;
int h, w;
struct node {
  int x;
  int y;
  int steps;
};
int v[21][21];
char a[21][21];
int main() {
  int i, j, maxv = 0, xpos, ypos;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  cin >> h >> w;
  node bfs[h * w + 1];
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) cin >> a[i][j];
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) {
      memset(bfs, 0, sizeof(bfs));
      memset(v, 0, sizeof(v));
      bfs[0].x = i;
      bfs[0].y = j;
      bfs[0].steps = 0;
      v[i][j] = 1;
      int f = 0, r = 0;
      while (f <= r) {
        for (int k = 0; k < 4; k++) {
          xpos = bfs[f].x + dx[k];
          ypos = bfs[f].y + dy[k];
          if (xpos > 0 && ypos > 0 && xpos <= h && ypos <= w &&
              a[xpos][ypos] == '.' && v[xpos][ypos] == 0) {
            r++;
            v[xpos][ypos] = 1;
            bfs[r].x = xpos;
            bfs[r].y = ypos;
            bfs[r].steps = bfs[f].steps + 1;
          }
        }
        f++;
      }
      if (bfs[r].steps > maxv) maxv = bfs[r].steps;
    }
  cout << maxv;
  return 0;
}
