#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T m, T n) {
  return n == 0 ? m : gcd(n, m % n);
}
template <typename T>
T lcm(T m, T n) {
  return n * m / gcd(n, m);
}
template <typename T>
T fact(T n) {
  return (n == 0 ? 1 : n * fact(n - 1));
}
template <typename T>
T modpow(T a, T e, T m) {
  return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m);
}
constexpr long long MOD = 1e9 + 7;
long long H, W;
long long dfs(long long x, long long y, long long ex, long long ey,
              vector<vector<long long>> _b) {
  if (x == ex && y == ey) {
    return 0;
  }
  if (x < 0 || H <= x || y < 0 || W <= y || _b[x][y] != 0) {
    return -1;
  }
  _b[x][y] = 1;
  long long a = dfs(x + 1, y, ex, ey, _b);
  long long b = dfs(x, y + 1, ex, ey, _b);
  long long c = dfs(x - 1, y, ex, ey, _b);
  long long d = dfs(x, y - 1, ex, ey, _b);
  long long res = -1;
  if (a != -1) {
    res = 1 + a;
    if (b != -1) res = min(res, 1 + b);
    if (c != -1) res = min(res, 1 + c);
    if (d != -1) res = min(res, 1 + d);
  } else {
    if (b != -1) {
      res = 1 + b;
      if (c != -1) res = min(res, 1 + c);
      if (d != -1) res = min(res, 1 + d);
    } else {
      if (c != -1) {
        res = 1 + c;
        if (d != -1) res = min(res, 1 + d);
      } else {
        if (d != -1) {
          res = 1 + d;
        }
      }
    }
  }
  return res;
}
signed main(void) {
  cin >> H >> W;
  vector<vector<long long>> b(H, vector<long long>(W, 0));
  for (long long i = 0; i < H; ++i) {
    string s;
    cin >> s;
    for (long long j = 0; j < W; ++j) {
      if (s[j] == '#') b[i][j] = -1;
    }
  }
  long long res = 0;
  for (long long sx = 0; sx < H; ++sx) {
    for (long long sy = 0; sy < W; ++sy) {
      for (long long ex = 0; ex < H; ++ex) {
        for (long long ey = 0; ey < W; ++ey) {
          if (sx == ex && sy == ey) continue;
          res = max(res, dfs(sx, sy, ex, ey, b));
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
