#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 5100000;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
const int MAX_N = 100000;
struct Edge {
  int to;
  int id;
};
const int D = 80 * 160 + 10;
const int D2 = D * 2;
int a[100][100];
bitset<D2> dp[90][90];
const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N, '#'));
int d[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 100000;
int bfs(int x, int y) {
  queue<pair<long long, long long>> que;
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      d[j][i] = INF;
    }
  }
  que.push(pair<long long, long long>(x, y));
  d[x][y] = 0;
  int mx = 0;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<long long, long long>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      if (d[j][i] == INF) continue;
      mx = max(mx, d[j][i]);
    }
  return mx;
}
int main() {
  h, w;
  cin >> h >> w;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      char c;
      cin >> c;
      maze[j][i] = c;
    }
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      if (maze[i][j] != '#') {
        ans = max(ans, bfs(j, i));
      }
    }
  cout << ans << endl;
  return 0;
}
