#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> S;
  vector<vector<int>> X;
  vector<int> x;
  for (int i = 0; i < (int)(2); i++) {
    for (int j = 0; j < (int)(W + 2); j++) {
      x.push_back(1000);
    }
    X.push_back(x);
  }
  for (int i = 0; i < (int)(H); i++) {
    string s;
    vector<int> x;
    cin >> s;
    S.push_back(s);
    for (int j = 0; j < (int)(W + 2); j++) {
      x.push_back(1000);
    }
    X.push_back(x);
  }
  int max = 0;
  for (int ii = 1; ii <= (int)(H); ii++) {
    for (int jj = 1; jj <= (int)(W); jj++) {
      X[ii][jj] = 0;
      int a = 0;
      for (int z = 0; z < (int)(H * W); z++) {
        for (int i = 1; i <= (int)(H); i++) {
          for (int j = 1; j <= (int)(W); j++) {
            if (S[i - 1][j - 1] == '.') {
              a = X[i][j - 1];
              if (a < 1000) {
                if (X[i][j] > a) {
                  X[i][j] = a + 1;
                }
              }
              a = X[i][j + 1];
              if (a < 1000) {
                if (X[i][j] > a) {
                  X[i][j] = a + 1;
                }
              }
              a = X[i + 1][j];
              if (a < 1000) {
                if (X[i][j] > a) {
                  X[i][j] = a + 1;
                }
              }
              a = X[i - 1][j];
              if (a < 1000) {
                if (X[i][j] > a) {
                  X[i][j] = a + 1;
                }
              }
              if (max < X[i][j]) {
                if (X[i][j] < 1000) {
                  max = X[i][j];
                }
              }
            }
          }
        }
      }
      for (int i = 1; i <= (int)(H); i++) {
        for (int j = 1; j <= (int)(W); j++) {
          X[i][j] = 1000;
        }
      }
    }
  }
  cout << max << endl;
  return 0;
}
