#include <bits/stdc++.h>
using namespace std;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int INF = 1e9;
const long long LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const long long mod = 1000000007;
int h, w;
char m[20][20];
int dfs(pair<int, int> s) {
  queue<tuple<int, int, int>> que;
  que.push(make_tuple(s.first, s.second, 0));
  int memo[20][20];
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) memo[i][j] = INF;
  memo[s.first][s.second] = 0;
  int ma = 0;
  while (!que.empty()) {
    tuple<int, int, int> t = que.front();
    que.pop();
    int x = get<0>(t);
    int y = get<1>(t);
    int c = get<2>(t);
    if (memo[x][y] > c) {
      memo[x][y] = c;
      ma = max(ma, c);
    }
    for (int i = 0; i < (int)(4); i++) {
      int nx = x + dx4[i], ny = y + dy4[i];
      if (nx >= 0 && nx <= (h - 1) && ny >= 0 && ny <= (w - 1)) {
        if (memo[nx][ny] == INF && m[nx][ny] == '.')
          que.push(make_tuple(nx, ny, c + 1));
      }
    }
  }
  return ma;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      cin >> m[i][j];
    }
  }
  int memo[20][20];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (m[i][j] == '.') ans = max(ans, dfs(pair<int, int>(i, j)));
      if (ans == 38) break;
    }
    if (ans == 38) break;
  }
  cout << ans << endl;
}
