#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, h, w;
  cin >> h >> w;
  a = 0;
  char b[h + 2][w + 2];
  int c[h + 2][w + 2];
  for (int i = 0; i < h + 2; i++) {
    b[i][0] = '#';
    b[i][w + 1] = '#';
  }
  for (int i = 0; i < w + 2; i++) {
    b[0][i] = '#';
    b[h + 1][i] = '#';
  }
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (b[i][j] == '.') {
        for (int k = 0; k < h + 2; k++) {
          for (int l = 0; l < w + 2; l++) {
            c[k][l] = 400;
          }
        }
        c[i][j] = 0;
        for (int k = 0; k < 400; k++) {
          for (int l = 1; l < h + 1; l++) {
            for (int m = 1; m < w + 1; m++) {
              if (b[l][m] == '.') {
                if (b[l][m - 1] == '.') c[l][m] = min(c[l][m], c[l][m - 1] + 1);
                if (b[l][m + 1] == '.') c[l][m] = min(c[l][m], c[l][m + 1] + 1);
                if (b[l - 1][m] == '.') c[l][m] = min(c[l][m], c[l - 1][m] + 1);
                if (b[l + 1][m] == '.') c[l][m] = min(c[l][m], c[l + 1][m] + 1);
              }
            }
          }
        }
        for (int k = 1; k < h + 1; k++) {
          for (int l = 1; l < w + 1; l++) {
            a = max(a, c[k][l]);
          }
        }
      }
    }
  }
  cout << a << endl;
}
