#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;
lli mod197 = 1000000007LL;
lli INF = 10000000000000;
template <typename T>
T extgcd(T a, T b, T& x, T& y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
lli graph[30][30] = {};
lli answer = 0;
void bfs(int x, int y) {
  bool visit[30][30] = {};
  queue<tlll> q;
  q.push(tlll(y, x, 0));
  while (!q.empty()) {
    auto t = q.front();
    q.pop();
    if (graph[std::get<0>(t)][std::get<1>(t)] == 1 &&
        visit[std::get<0>(t)][std::get<1>(t)] == false) {
      answer = max(answer, std::get<2>(t));
      visit[std::get<0>(t)][std::get<1>(t)] = true;
      q.push(tlll(std::get<0>(t) + 1, std::get<1>(t), get<2>(t) + 1));
      q.push(tlll(std::get<0>(t) - 1, std::get<1>(t), get<2>(t) + 1));
      q.push(tlll(std::get<0>(t), std::get<1>(t) - 1, get<2>(t) + 1));
      q.push(tlll(std::get<0>(t), std::get<1>(t) + 1, get<2>(t) + 1));
    }
  }
}
int main(void) {
  lli h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        graph[i + 1][j + 1] = 1;
      }
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (graph[i][j] == 1) bfs(i, j);
    }
  }
  cout << answer << endl;
  return 0;
}
