#include <bits/stdc++.h>
using namespace std;
int h, w;
char s[23][25];
int did[23][25];
int ans = 0;
void step(int x, int y, int num) {
  if (s[x][y] == '#') {
    return;
  }
  if (did[x][y] <= num) {
    return;
  }
  did[x][y] = num;
  step(x + 1, y, num + 1);
  step(x - 1, y, num + 1);
  step(x, y + 1, num + 1);
  step(x, y - 1, num + 1);
  return;
}
void allfalse(void) {
  int i, j;
  for (i = 0; i < 23; i++) {
    for (j = 0; j < 25; j++) {
      did[i][j] = 500;
    }
  }
}
void calc(void) {
  int i, j;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (did[i][j] != 50) {
        ans = max(ans, did[i][j]);
      }
    }
  }
}
int main() {
  int i, j;
  int ii, jj;
  string in;
  cin >> h >> w;
  for (i = 1; i <= h; i++) {
    cin >> in;
    s[i][0] = '#';
    for (j = 1; j <= in.length(); j++) {
      s[i][j] = in[j - 1];
    }
    s[i][j] = '#';
    s[i][j + 1] = NULL;
  }
  for (i = 0; i <= w + 1; i++) {
    s[0][i] = '#';
    s[h + 1][i] = '#';
  }
  s[0][i] = s[h + 1][i] = NULL;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (s[i][j] == '.') {
        allfalse();
        step(i, j, 0);
        calc();
      }
    }
  }
  cout << ans << endl;
  return 0;
}
