#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  long long h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (long long i = 0; i < (long long)(h); i++) {
    for (long long j = 0; j < (long long)(w); j++) {
      cin >> s[i][j];
    }
  }
  long long mx = 0;
  for (long long i = 0; i < (long long)(h); i++) {
    for (long long j = 0; j < (long long)(w); j++) {
      if (s[i][j] == '.') {
        queue<pair<long long, long long>> q;
        vector<vector<long long>> d(h, vector<long long>(w, 0));
        q.push(make_pair(i, j));
        while (!q.empty()) {
          pair<long long, long long> p = q.front();
          q.pop();
          long long fr = p.first, sc = p.second;
          mx = max(mx, d[fr][sc]);
          if (fr > 0 && s[fr - 1][sc] == '.' && d[fr - 1][sc] == 0) {
            q.push(make_pair(fr - 1, sc));
            d[fr - 1][sc] = d[fr][sc] + 1;
          }
          if (fr < h - 1 && s[fr + 1][sc] == '.' && d[fr + 1][sc] == 0) {
            q.push(make_pair(fr + 1, sc));
            d[fr + 1][sc] = d[fr][sc] + 1;
          }
          if (sc > 0 && s[fr][sc - 1] == '.' && d[fr][sc - 1] == 0) {
            q.push(make_pair(fr, sc - 1));
            d[fr][sc - 1] = d[fr][sc] + 1;
          }
          if (sc < w - 1 && s[fr][sc + 1] == '.' && d[fr][sc + 1] == 0) {
            q.push(make_pair(fr, sc + 1));
            d[fr][sc + 1] = d[fr][sc] + 1;
          }
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
