#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
void warshall_floyd(Graph &graph) {
  int V = graph.size();
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
      }
    }
  }
}
ll to_id(ll x, ll y) { return 25 * x + y; }
void Main() {
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  for (ll i = 0; i < (ll)(H); i++) cin >> grid[i];
  Graph graph(500, vector<ll>(500, INF));
  for (ll i = 0; i < (ll)(H); i++) {
    for (ll j = 0; j < (ll)(W); j++) {
      if (grid[i][j] == '#') continue;
      for (ll k = 0; k < (ll)(4); k++) {
        int x = dx[k];
        int y = dy[k];
        if (0 <= j + y && j + y < W && 0 <= i + x && i + x < H &&
            grid[i + x][j + y] != '#') {
          ll from = to_id(i, j);
          ll to = to_id(i + x, j + y);
          graph[from][to] = 1;
          graph[to][from] = 1;
        }
      }
    }
  }
  warshall_floyd(graph);
  ll ans = 0;
  for (ll i = 0; i < (ll)(H); i++) {
    for (ll j = 0; j < (ll)(W); j++) {
      ll start = to_id(i, j);
      if (grid[i][j] == '#') continue;
      for (ll i2 = 0; i2 < (ll)(H); i2++) {
        for (ll j2 = 0; j2 < (ll)(W); j2++) {
          ll goal = to_id(i2, j2);
          if (grid[i2][j2] == '#') continue;
          ll tmp = graph[start][goal];
          ll tmp2 = graph[goal][start];
          if (tmp < INF / 2) {
            ans = max(tmp, ans);
          }
          if (tmp2 < INF / 2) {
            ans = max(tmp2, ans);
          }
        }
      }
    }
  }
  if (ans <= 500) {
    cout << ans << '\n';
  } else {
    cout << 0 << '\n';
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
