#include <bits/stdc++.h>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using namespace std;
int main() {
  ll H, W;
  cin >> H >> W;
  bool m[H][W];
  ll tmpm[H][W];
  for (int yi = 0; yi < H; yi++) {
    string s;
    cin >> s;
    for (int xi = 0; xi < W; xi++) {
      m[yi][xi] = (s[xi] == '.');
      tmpm[yi][xi] = -1;
    }
  }
  queue<pair<ll, ll>> q = queue<pair<ll, ll>>();
  ll M = 0;
  for (int Ys = 0; Ys < H; Ys++) {
    for (int Xs = 0; Xs < W; Xs++) {
      if (!m[Ys][Xs]) {
        continue;
      }
      q.push(make_pair(Ys, Xs));
      tmpm[Ys][Xs] = 0;
      while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int Y = p.first;
        int X = p.second;
        if (!m[Y][X]) {
          continue;
        }
        if (Y != 0 && tmpm[Y - 1][X] == -1) {
          tmpm[Y - 1][X] = tmpm[Y][X] + 1;
          q.push(make_pair(Y - 1, X));
        }
        if (Y != H - 1 && tmpm[Y + 1][X] == -1) {
          tmpm[Y + 1][X] = tmpm[Y][X] + 1;
          q.push(make_pair(Y + 1, X));
        }
        if (X != 0 && tmpm[Y][X - 1] == -1) {
          tmpm[Y][X - 1] = tmpm[Y][X] + 1;
          q.push(make_pair(Y, X - 1));
        }
        if (Y != W - 1 && tmpm[Y][X + 1] == -1) {
          tmpm[Y][X + 1] = tmpm[Y][X] + 1;
          q.push(make_pair(Y, X + 1));
        }
      }
      for (int yi = 0; yi < H; yi++) {
        for (int xi = 0; xi < W; xi++) {
          M = max(M, tmpm[yi][xi]);
          tmpm[yi][xi] = -1;
        }
      }
    }
  }
  cout << M;
}
