#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200000;
long long H, W, ans = 0;
vector<char> v(22, '#');
vector<vector<char>> S(22, v);
void bfs(long long sx, long long sy, long long gx, long long gy) {
  queue<pair<long long, long long>> Q;
  vector<long long> vc(H + 2, 0);
  vector<vector<long long>> color(W + 2, vc), cost(W + 2, vc);
  Q.push(make_pair(sx, sy));
  color[sx][sy] = 1;
  cost[sx][sy] = 0;
  while (!Q.empty()) {
    pair<long long, long long> p = Q.front();
    Q.pop();
    if (color[p.first + 1][p.second] == 0 && S[p.first + 1][p.second] == '.') {
      Q.push(make_pair(p.first + 1, p.second));
      color[p.first + 1][p.second] = 1;
      cost[p.first + 1][p.second] = cost[p.first][p.second] + 1;
    }
    if (color[p.first - 1][p.second] == 0 && S[p.first - 1][p.second] == '.') {
      Q.push(make_pair(p.first - 1, p.second));
      color[p.first - 1][p.second] = 1;
      cost[p.first - 1][p.second] = cost[p.first][p.second] + 1;
    }
    if (color[p.first][p.second + 1] == 0 && S[p.first][p.second + 1] == '.') {
      Q.push(make_pair(p.first, p.second + 1));
      color[p.first][p.second + 1] = 1;
      cost[p.first][p.second + 1] = cost[p.first][p.second] + 1;
    }
    if (color[p.first][p.second - 1] == 0 && S[p.first][p.second - 1] == '.') {
      Q.push(make_pair(p.first, p.second - 1));
      color[p.first][p.second - 1] = 1;
      cost[p.first][p.second - 1] = cost[p.first][p.second] + 1;
    }
  }
  ans = max(ans, cost[gx][gy]);
}
void bfsinit() {
  for (long long i1 = 1; i1 <= H; i1++) {
    for (long long j1 = 1; j1 <= W; j1++) {
      for (long long i2 = 1; i2 <= H; i2++) {
        for (long long j2 = 1; j2 <= W; j2++) {
          bfs(j2, i2, j1, i1);
        }
      }
    }
  }
}
signed main() {
  cin >> H >> W;
  for (long long j = 1; j <= H; j++) {
    for (long long i = 1; i <= W; i++) cin >> S[i][j];
  }
  bfsinit();
  cout << ans << endl;
  return 0;
}
