#include <bits/stdc++.h>
const long long INF = 99999999999999;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long number1, long long number2) {
  return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v) {
  return s.find(v) != std::string::npos;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') return c - '0';
  return 0;
}
using namespace std;
unsigned GetDigit(unsigned num) { return std::to_string(num).length(); }
int H, W;
int sx, sy;
int gx, gy;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vector<string> s(H + 100);
int bfs() {
  queue<pair<int, int> > que;
  int cnt[H][W];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cnt[i][j] = -1;
    }
  }
  que.push(pair<int, int>(sx, sy));
  cnt[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int i = 0; i < 4; ++i) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && s[nx][ny] != '#' &&
          cnt[nx][ny] == -1) {
        que.push(pair<int, int>(nx, ny));
        cnt[nx][ny] = cnt[p.first][p.second] + 1;
      }
    }
  }
  return cnt[gx][gy];
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) cin >> s[i];
  int ans = 0;
  for (long long(i) = 0; (i) < (H); (i)++) {
    for (long long(j) = 0; (j) < (W); (j)++) {
      for (long long(k) = 0; (k) < (H); (k)++) {
        for (long long(l) = 0; (l) < (W); (l)++) {
          sx = i;
          sy = j;
          gx = k;
          gy = l;
          ans = max(bfs(), ans);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
