#include <bits/stdc++.h>
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
vint dx = {1, 0, -1, 0};
vint dy = {0, 1, 0, -1};
int h, w;
vector<string> field;
void bfs(P s, P g, vvint &dis) {
  if (s == g) return;
  for (int i = 0; i < (int)(4); i++) {
    int n_x = s.second + dx[i];
    int n_y = s.first + dy[i];
    if (n_x >= 0 && n_x < w && n_y >= 0 && n_y < h && field[n_y][n_x] != '#') {
      if (chmin(dis[n_y][n_x], dis[s.first][s.second] + 1)) {
        bfs(P(n_y, n_x), g, dis);
      }
    }
  }
}
int main() {
  cin >> h >> w;
  field.resize(h);
  for (int i = 0; i < (int)(h); i++) cin >> field[i];
  P s, g;
  int ans = -1;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (field[i][j] == '#') continue;
      s = P(i, j);
      for (int k = 0; k < (int)(h); k++)
        for (int l = 0; l < (int)(w); l++) {
          if (field[k][l] == '#') continue;
          g = P(k, l);
          vvint dis(h, vint(w, inf));
          dis[s.first][s.second] = 0;
          bfs(s, g, dis);
          if (dis[g.first][g.second] != inf) {
            ans = max(ans, dis[g.first][g.second]);
          }
        }
    }
  cout << ans << endl;
}
