#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll h, w, sx, sy, gx, gy;
const ll INF = 1e9 + 7;
vector<string> maze(50);
vector<vector<ll>> a(50, vector<ll>(50));
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll bfs() {
  queue<pair<ll, ll>> que;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      a[i][j] = INF;
    }
  }
  que.push(pair<ll, ll>(sy, sx));
  a[sy][sx] = 0;
  while (que.size()) {
    pair<ll, ll> p = que.front();
    que.pop();
    if (p.first == gy && p.second == gx) break;
    for (int i = 0; i < 4; i++) {
      ll ny = dy[i] + p.first, nx = dx[i] + p.second;
      if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] == '.' &&
          a[ny][nx] == INF) {
        que.push(pair<ll, ll>(ny, nx));
        a[ny][nx] = a[p.first][p.second] + 1;
      }
    }
  }
  return a[gy][gx];
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cin >> h >> w;
  for (ll i = 0; i < h; i++) {
    cin >> maze[i];
  }
  vector<pair<ll, ll>> dot;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (maze[i][j] == '.') dot.emplace_back(make_pair(j, i));
    }
  }
  sort(dot.begin(), dot.end());
  ll ans = 0;
  for (ll i = 0; i < dot.size(); i++) {
    for (ll j = dot.size(); 0 <= j; j--) {
      sx = dot[i].first;
      sy = dot[i].second;
      gx = dot[j].first;
      gy = dot[j].second;
      ans = max(bfs(), ans);
    }
  }
  cout << ans << endl;
}
