#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int MAX = 500000;
const int inf = 1000000007;
const long long mod = 1000000007;
const long long longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w;
int ans;
string s[25];
int main() {
  cin >> h >> w;
  for (int i = (int)(0); i < (int)(h); ++i) cin >> s[i];
  for (int i = (int)(0); i < (int)(h); ++i) {
    for (int j = (int)(0); j < (int)(w); ++j) {
      if (s[i][j] != '#') {
        queue<pair<int, int> > point;
        bool f[25][25];
        for (int i = (int)(0); i < (int)(h); ++i)
          for (int j = (int)(0); j < (int)(w); ++j) f[j][i] = true;
        int cnt[25][25];
        cnt[j][i] = 0;
        point.push(make_pair(i, j));
        while (!point.empty()) {
          int x = point.front().second, y = point.front().first;
          point.pop();
          f[x][y] = false;
          for (int k = (int)(0); k < (int)(4); ++k) {
            if (x + dx[k] >= 0 && y + dy[k] >= 0 && x + dx[k] < w &&
                y + dy[k] < h && s[y + dy[k]][x + dx[k]] != '#' &&
                f[x + dx[k]][y + dy[k]]) {
              cnt[x + dx[k]][y + dy[k]] = cnt[x][y] + 1;
              point.push(make_pair(y + dy[k], x + dx[k]));
            }
          }
          ans = max(ans, cnt[x][y]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
