#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int a, long long int mod) {
  long long int res = a % mod;
  if (res < 0) res = res + mod;
  return res;
}
long long int modpow(long long int a, long long int n, long long int mod) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long int modinv(long long int a, long long int mod) {
  return modpow(a, mod - 2, mod);
}
bool is_prime(long long int n) {
  long long int i = 2;
  if (n == 1) return false;
  if (n == 2) return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }
  if (n % i == 0) res = false;
  return res;
}
int H, W;
vector<int> V[400];
string S[20];
vector<int> isVisited;
int id(int i, int j) { return i * W + j; }
void gen_map() {
  for (long long int i = 0; i < (H); i++) {
    for (long long int j = 0; j < (W); j++) {
      if (S[i][j] == '.') {
        if (i - 1 >= 0) V[id(i - 1, j)].push_back(id(i, j));
        if (i + 1 < H) V[id(i + 1, j)].push_back(id(i, j));
        if (j - 1 >= 0) V[id(i, j - 1)].push_back(id(i, j));
        if (j + 1 < W) V[id(i, j + 1)].push_back(id(i, j));
      }
    }
  }
}
long long int bfs(long long int current, long long int from) {
  long long int s = V[current].size();
  long long int longest = 0;
  isVisited[current] = 1;
  vector<pair<long long int, long long int>> way;
  way.push_back({current, 0});
  long long int pos = 0;
  long long int maxlen = 0;
  while (true) {
    if (pos >= way.size()) break;
    long long int curpos = way[pos].first;
    long long int curlen = way[pos].second;
    s = V[curpos].size();
    for (long long int i = 0; i < (s); i++) {
      long long int a = V[curpos][i];
      if (isVisited[a] == 1) continue;
      way.push_back({a, curlen + 1});
      maxlen = max(maxlen, curlen + 1);
      isVisited[a] = 1;
    }
    pos++;
  }
  return maxlen;
}
int main() {
  cin >> H >> W;
  for (long long int i = 0; i < (H); i++) cin >> S[i];
  gen_map();
  long long int ans = 0;
  for (long long int i = 0; i < (H * W); i++) {
    isVisited = vector<int>(H * W, 0);
    isVisited[i] = 1;
    ans = max(ans, bfs(i, -1));
  }
  cout << ans;
  return 0;
}
