#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int INF = 1e9;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int lx, int ux, int ly, int uy, int x, int y) {
  return lx <= x && x < ux && ly <= y && y < uy;
}
long long int power(long long int x, long long int p) {
  if (p == 0) return 1;
  long long int res = power(x * x % mod, p / 2);
  if (p % 2 == 1) res = res * x % mod;
  return res;
}
int h, w;
int bfs(int sh, int sw, vector<string> g) {
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<pair<int, int>> que;
  que.push(pair<int, int>(sh, sw));
  dist[sh][sw] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    int d = dist[x][y];
    for (int i = 0; i < (4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (valid(0, h, 0, w, nx, ny) && g[nx][ny] != '#') {
        if (dist[nx][ny] == INF) {
          dist[nx][ny] = dist[x][y] + 1;
          que.push(pair<int, int>(nx, ny));
        }
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (dist[i][j] < INF) ret = max(ret, dist[i][j]);
    }
  return ret;
}
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); ++i) cin >> s[i];
  int ans = 0;
  for (int sh = 0; sh < (h); ++sh) {
    for (int sw = 0; sw < (w); ++sw) {
      ans = max(ans, bfs(sh, sw, s));
    }
  }
  cout << ans << endl;
  return 0;
}
