#include <bits/stdc++.h>
using namespace std;
char maze[20][20];
int H, W;
int getMoves(int sx, int sy) {
  int dirx[] = {0, 0, 1, -1};
  int diry[] = {1, -1, 0, 0};
  queue<pair<int, int> > poss;
  poss.push(pair<int, int>(sx, sy));
  map<pair<int, int>, int> steps;
  steps[pair<int, int>(sx, sy)] = 0;
  int step = 0;
  while (!poss.empty()) {
    pair<int, int> pos = poss.front();
    poss.pop();
    for (int i = 0; i < 4; i++) {
      int gx = pos.first + dirx[i];
      int gy = pos.second + diry[i];
      if (gx >= 0 && gx < H && gy >= 0 && gy < W && maze[gx][gy] == '.') {
        if (steps[pair<int, int>(gx, gy)] == 0) {
          steps[pair<int, int>(gx, gy)] =
              steps[pair<int, int>(pos.first, pos.second)] + 1;
          poss.push(pair<int, int>(gx, gy));
          if (step < steps[pair<int, int>(gx, gy)])
            step = steps[pair<int, int>(gx, gy)];
        }
      }
    }
  }
  return step;
}
int main() {
  {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> maze[i][j];
      }
    }
    int maxMoves = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (maze[i][j] == '.') {
          int moves = getMoves(i, j);
          if (maxMoves < moves) maxMoves = moves;
        }
      }
    }
    cout << maxMoves << endl;
  }
  return 0;
}
