#include <bits/stdc++.h>
using namespace std;
int main() {
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  int H, W;
  int maxD = 0;
  cin >> H >> W;
  H--;
  W--;
  string S;
  char maze[W + 1][H + 1];
  int D[W + 1][H + 1];
  for (int i = 0; i <= H; i++) {
    for (int j = 0; j <= W; j++) {
      D[j][i] = 1000;
    }
  }
  for (int i = 0; i <= H; i++) {
    cin >> S;
    for (int j = 0; j <= W; j++) {
      maze[j][i] = S.at(j);
    }
  }
  for (int wi = 0; wi < W; wi++) {
    for (int hi = 0; hi < H; hi++) {
      for (int i = 0; i <= H; i++) {
        for (int j = 0; j <= W; j++) {
          D[j][i] = 1000;
        }
      }
      D[wi][hi] = 0;
      queue<pair<int, int> > que;
      que.push(pair<int, int>(wi, hi));
      while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          int nx = p.first + dx[i], ny = p.second + dy[i];
          if (0 <= nx && nx <= W && 0 <= ny && ny <= H && maze[nx][ny] == '.' &&
              D[nx][ny] == 1000) {
            que.push(pair<int, int>(nx, ny));
            D[nx][ny] = D[p.first][p.second] + 1;
          }
        }
      }
      for (int i = 0; i <= H; i++) {
        for (int j = 0; j <= W; j++) {
          if (maze[j][i] == '.') {
            maxD = max(maxD, D[j][i]);
          }
        }
      }
    }
  }
  cout << maxD << endl;
  return 0;
}
