#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
vector<string> A;
int solve(int starty, int startx, int endy, int endx, vector<vector<bool>> x) {
  if (starty == endy && startx == endx) {
    return 0;
  }
  int MIN = 2e9;
  for (int i = 0; i < 4; i++) {
    if (starty + dy[i] < 0 || startx + dx[i] < 0 || starty + dy[i] > H - 1 ||
        startx + dx[i] > W - 1 ||
        x.at(starty + dy[i]).at(startx + dx[i]) != true ||
        A.at(starty + dy[i]).at(startx + dx[i]) == '#') {
      continue;
    }
    x.at(starty + dy[i]).at(startx + dx[i]) = false;
    MIN = min(MIN, solve(starty + dy[i], startx + dx[i], endy, endx, x) + 1);
  }
  return MIN;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    A.push_back(s);
  }
  int MAX = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A.at(i).at(j) == '#') {
        continue;
      }
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if (A.at(k).at(l) == '#') {
            continue;
          }
          vector<vector<bool>> x(H, vector<bool>(W, true));
          x.at(i).at(j) = false;
          int cnt = solve(i, j, k, l, x);
          MAX = max(MAX, cnt);
        }
      }
    }
  }
  cout << MAX << endl;
}
