#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MAX = 200000;
template <typename T>
T gcd(T a, T b) {
  return b != 0 ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int maxx = -1;
  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      if (S[a][b] == '#') {
        continue;
      }
      int tmp = 0;
      queue<pair<int, int> > ff;
      ff.push(make_pair(a, b));
      int flag[H][W];
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          flag[i][j] = -1;
        }
      }
      flag[a][b] = 1;
      while (!ff.empty()) {
        vector<pair<int, int> > ppp;
        while (!ff.empty()) {
          ppp.push_back(ff.front());
          ff.pop();
        }
        for (int i = 0; i < ppp.size(); i++) {
          pair<int, int> ll = ppp[i];
          if (ll.first - 1 >= 0) {
            if (flag[ll.first - 1][ll.second] == -1 &&
                S[ll.first - 1][ll.second] == '.') {
              ff.push(make_pair(ll.first - 1, ll.second));
            }
          }
          if (ll.first + 1 < H) {
            if (flag[ll.first + 1][ll.second] == -1 &&
                S[ll.first + 1][ll.second] == '.') {
              ff.push(make_pair(ll.first + 1, ll.second));
            }
          }
          if (ll.second - 1 >= 0) {
            if (flag[ll.first][ll.second - 1] == -1 &&
                S[ll.first][ll.second - 1] == '.') {
              ff.push(make_pair(ll.first, ll.second - 1));
            }
          }
          if (ll.second + 1 < W) {
            if (flag[ll.first][ll.second + 1] == -1 &&
                S[ll.first][ll.second + 1] == '.') {
              ff.push(make_pair(ll.first, ll.second + 1));
            }
          }
          flag[ll.first][ll.second] = 1;
        }
        tmp++;
      }
      if (tmp > maxx) {
        maxx = tmp;
      }
    }
  }
  cout << maxx - 1 << endl;
}
