#include <bits/stdc++.h>
using namespace std;
struct IoSetup {
  IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
} IoSetup;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
static constexpr const signed int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
inline bool inside(int x, int y, int w, int h) {
  return (x >= 0 && y >= 0 && x < w && y < h);
}
template <class T>
bool chmax(T &a, const T &b) {
  return (a = max(a, b)) == b;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (a = min(a, b)) == b;
}
inline int qp(int a, long long b, int mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int h, w;
string s[25];
int mem[30][30];
int bfs(int sx, int sy) {
  memset(mem, 0x3f, sizeof(mem));
  mem[sy][sx] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  int maxi = 0;
  while (!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (inside(nx, ny, w, h) && s[ny][nx] != '#' && mem[ny][nx] == INF) {
        mem[ny][nx] = mem[y][x] + 1;
        chmax(maxi, mem[ny][nx]);
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  return maxi;
}
signed main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int maxi = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#') chmax(maxi, bfs(i, j));
    }
  }
  cout << maxi << endl;
  return 0;
}
