#include <bits/stdc++.h>
using namespace std;
long long get() {
  long long r;
  cin >> r;
  return r;
}
string getstr() {
  string r;
  cin >> r;
  return r;
}
long long h, w, ans;
char map[30][30];
queue<pair<pair<long long, long long>, long long>> q;
long long mapi[30][30];
signed main() {
  cin >> h >> w;
  for (long long i = 1; i <= (h); i++)
    for (long long j = 1; j <= (w); j++) cin >> map[i][j];
  for (long long x1 = 1; x1 <= (h); x1++)
    for (long long y1 = 1; y1 <= (w); y1++) {
      q.empty();
      for (long long i = 1; i <= (h); i++)
        for (long long j = 1; j <= (w); j++) mapi[i][j] = 1000000007;
      q.push(make_pair(make_pair(x1, y1), 0));
      while (q.size()) {
        long long x = q.front().first.first, y = q.front().first.second,
                  c = q.front().second;
        q.pop();
        if (mapi[x][y] > c) mapi[x][y] = c;
        long long xp = x - 1, yp = y;
        if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' &&
            mapi[xp][yp] > c + 1)
          q.push(make_pair(make_pair(xp, yp), c + 1));
        xp = x + 1;
        if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' &&
            mapi[xp][yp] > c + 1)
          q.push(make_pair(make_pair(xp, yp), c + 1));
        xp = x;
        yp = y - 1;
        if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' &&
            mapi[xp][yp] > c + 1)
          q.push(make_pair(make_pair(xp, yp), c + 1));
        yp = y + 1;
        if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' &&
            mapi[xp][yp] > c + 1)
          q.push(make_pair(make_pair(xp, yp), c + 1));
      }
      for (long long i = 1; i <= (h); i++)
        for (long long j = 1; j <= (w); j++)
          if (map[i][j] == '.') ans = max(ans, mapi[i][j]);
    }
  cout << ans << endl;
}
