#include <bits/stdc++.h>
using namespace std;
const long long maxn = 40;
const long long mod = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
long long pw(long long a, long long b) {
  return (!b ? 1
             : (b & 1 ? a * pw(a * a % mod, b / 2) % mod
                      : pw(a * a % mod, b / 2) % mod));
}
int mx = 0, h, w;
int dist[maxn][maxn];
bool mark[maxn][maxn];
string s[maxn];
queue<pair<int, int> > q;
void solve(int x, int y) {
  memset(mark, 0, sizeof mark);
  ;
  dist[x][y] = 0;
  mark[x][y] = 0;
  q.push(pair<int, int>(x, y));
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (s[cur.first][cur.second] == '#') continue;
    mx = max(mx, dist[cur.first][cur.second]);
    if (cur.first < h - 1 and !mark[cur.first + 1][cur.second]) {
      mark[cur.first + 1][cur.second] = 1;
      dist[cur.first + 1][cur.second] = dist[cur.first][cur.second] + 1;
      q.push(pair<int, int>(cur.first + 1, cur.second));
    }
    if (cur.first > 0 and !mark[cur.first - 1][cur.second]) {
      mark[cur.first - 1][cur.second] = 1;
      dist[cur.first - 1][cur.second] = dist[cur.first][cur.second] + 1;
      q.push(pair<int, int>(cur.first - 1, cur.second));
    }
    if (cur.second < w - 1 and !mark[cur.first][cur.second + 1]) {
      mark[cur.first][cur.second + 1] = 1;
      dist[cur.first][cur.second + 1] = dist[cur.first][cur.second] + 1;
      q.push(pair<int, int>(cur.first, cur.second + 1));
    }
    if (cur.second > 0 and !mark[cur.first][cur.second - 1]) {
      mark[cur.first][cur.second - 1] = 1;
      dist[cur.first][cur.second - 1] = dist[cur.first][cur.second] + 1;
      q.push(pair<int, int>(cur.first, cur.second - 1));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      solve(i, j);
    }
  }
  cout << mx;
  return (0);
}
