#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int x;
  int y;
  int dist;
} X;
int ds[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main(int argc, char const *argv[]) {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  X *ans = new X{0, 0, 0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      queue<X *> q;
      int used[H][W];
      auto _x = new X{j, i, 0};
      X *max = _x;
      q.push(_x);
      while (!q.empty()) {
        auto x = q.front();
        q.pop();
        if (used[x->y][x->x] == 1) continue;
        used[x->y][x->x] = 1;
        for (int aa = 0; aa < 4; aa++) {
          int nx = x->x + ds[aa][0];
          int ny = x->y + ds[aa][1];
          if (0 <= nx && nx < W && 0 <= ny && ny < H && S[ny][nx] != '#') {
            auto x2 = new X{nx, ny, x->dist + 1};
            if (used[x2->y][x2->x] == 1) continue;
            q.push(x2);
            if (max->dist <= x2->dist) {
              max = x2;
            }
          }
        }
      }
      if (ans->dist < max->dist) {
        ans = max;
      }
    }
  }
  cout << ans->dist << endl;
  return 0;
}
