#include <bits/stdc++.h>
using namespace std;
int main() {
  int sx;
  int sy;
  int gx;
  int gy;
  int INF = 999999;
  vector<vector<int>> count(21, vector<int>(21));
  vector<vector<int>> count_(21, vector<int>(21));
  deque<pair<int, int>> que;
  vector<int> dx = {0, 1, 0, -1};
  vector<int> dy = {1, 0, -1, 0};
  int H, W;
  cin >> H >> W;
  vector<string> S;
  S.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count_[i][j] = INF;
    }
  }
  count = count_;
  int answer = 0;
  for (int j = 0; j < H; j++) {
    for (int k = 0; k < W; k++) {
      if (S[j][k] == '.') {
        sx = k;
        sy = j;
        for (int j2 = 0; j2 < H; j2++) {
          for (int k2 = 0; k2 < W; k2++) {
            if (S[j2][k2] == '.' && (sx != k2 && sy != j2)) {
              gx = k2;
              gy = j2;
              count = count_;
              que.clear();
              que.push_back(make_pair(sy, sx));
              count[sy][sx] = 0;
              while (!que.empty()) {
                pair<int, int> p = que.front();
                que.pop_front();
                if (p.second == gx && p.first == gy) {
                  break;
                }
                for (int i = 0; i < 4; i++) {
                  int dx_ = p.second + dx[i];
                  int dy_ = p.first + dy[i];
                  if (0 <= dy_ && dy_ < H && 0 <= dx_ && dx_ < W &&
                      count[dy_][dx_] == INF && S[dy_][dx_] == '.') {
                    count[dy_][dx_] = count[p.first][p.second] + 1;
                    que.push_back(make_pair(dy_, dx_));
                  }
                }
              }
              answer = max(answer, count[gy][gx]);
            }
          }
        }
      }
    }
  }
  cout << answer << endl;
}
