#include <bits/stdc++.h>
using namespace std;
char s[21][21];
int main() {
  int h, w;
  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 i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        continue;
      }
      int mark[20][20] = {0};
      int step[20][20] = {0};
      int dx[4] = {0, 1, 0, -1};
      int dy[4] = {-1, 0, 1, 0};
      int qx[4010] = {0};
      int qy[4010] = {0};
      int head = 0;
      int tail = 0;
      qx[head] = j;
      qy[head] = i;
      head++;
      while (head != tail) {
        int x = qx[tail];
        int y = qy[tail];
        tail++;
        for (int k = 0; k < 4; k++) {
          int tx = x + dx[k];
          int ty = y + dy[k];
          if (tx < 0 || ty < 0 || tx >= w || ty >= h) {
            continue;
          }
          if (mark[ty][tx]) {
            continue;
          }
          if (s[ty][tx] == '.') {
            qx[head] = tx;
            qy[head] = ty;
            head++;
            mark[ty][tx] = 1;
            step[ty][tx] = step[y][x] + 1;
            ans = max(ans, step[ty][tx]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
