#include <bits/stdc++.h>
using namespace std;
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename C>
i64 SIZE(const C &c) {
  return static_cast<i64>(c.size());
}
template <typename T, size_t N>
i64 SIZE(const T (&)[N]) {
  return static_cast<i64>(N);
}
struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(IOS_PREC);
    if (AUTOFLUSH) cout << unitbuf;
  }
} PROCON_INIT;
i64 H, W;
char G[20][20];
i64 d[20][20];
i64 dy[] = {-1, 0, 1, 0};
i64 dx[] = {0, -1, 0, 1};
bool inside(i64 y, i64 x) { return (0 <= y && y < H && 0 <= x && x < W); }
i64 bfs(i64 sy, i64 sx) {
  i64 maxd = 0;
  queue<pair<i64, i64> > que;
  for (i64 y = (0), yxxxx_end = (H); y < yxxxx_end; ++y) {
    for (i64 x = (0), xxxxx_end = (W); x < xxxxx_end; ++x) {
      d[y][x] = 1152921504606846976;
    }
  }
  que.push(make_pair(sy, sx));
  d[sy][sx] = 0;
  i64 ny, nx;
  while (!que.empty()) {
    pair<i64, i64> yx = que.front();
    que.pop();
    for (i64 i = (0), ixxxx_end = (4); i < ixxxx_end; ++i) {
      ny = yx.first + dy[i];
      nx = yx.second + dx[i];
      if (inside(ny, nx) && d[ny][nx] == 1152921504606846976 &&
          G[ny][nx] == '.') {
        que.push(make_pair(ny, nx));
        d[ny][nx] = d[yx.first][yx.second] + 1;
        chmax(maxd, d[ny][nx]);
      }
    }
  }
  return maxd;
}
void solve() {
  i64 maxd = 0;
  for (i64 sy = (0), syxxxx_end = (H); sy < syxxxx_end; ++sy) {
    for (i64 sx = (0), sxxxxx_end = (W); sx < sxxxxx_end; ++sx) {
      chmax(maxd, bfs(sy, sx));
    }
  }
  cout << maxd << endl;
}
int main() {
  cin >> H >> W;
  for (i64 y = (0), yxxxx_end = (H); y < yxxxx_end; ++y) {
    for (i64 x = (0), xxxxx_end = (W); x < xxxxx_end; ++x) {
      cin >> G[y][x];
    }
  }
  solve();
  return 0;
}
