#include <bits/stdc++.h>
using namespace std;
int H, W, mxdist = 0;
vector<vector<char>> S(20, vector<char>(20));
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
void bfs(pair<int, int> pos, pair<int, int> ppos, int dist,
         vector<vector<int>> &_checked) {
  int px = ppos.second, py = ppos.first;
  _checked.at(pos.first).at(pos.second) =
      min(_checked.at(pos.first).at(pos.second), dist);
  dist++;
  for (int i = 0; i < 4; i++) {
    int x = pos.second + dx.at(i), y = pos.first + dy.at(i);
    if (y >= 0 && x >= 0 && y < H && x < W && dist < _checked.at(y).at(x)) {
      if (!(x == px && y == py) && S.at(y).at(x) == '.')
        bfs(pair<int, int>(y, x), pos, dist, _checked);
    }
  }
}
int main() {
  int i, j;
  cin >> H >> W;
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      vector<vector<int>> checked(H, vector<int>(W, 401));
      if (S.at(i).at(j) == '#') continue;
      bfs(pair<int, int>(i, j), pair<int, int>(-1, -1), 0, checked);
      for (int _i = 0; _i < H; _i++) {
        for (int _j = 0; _j < H; _j++) {
          if (mxdist <= checked.at(_i).at(_j) && checked.at(_i).at(_j) != 401)
            mxdist = checked.at(_i).at(_j);
        }
      }
    }
  }
  cout << mxdist << endl;
}
