#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
  cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ", ";
  cetak(v...);
}
const int MOD = 1e9 + 7;
int add(int x, int y) {
  int ret = x + y;
  if (ret >= MOD) ret -= MOD;
  return ret;
}
int sub(int x, int y) {
  int ret = x - y;
  if (ret < 0) ret += MOD;
  return ret;
}
int mul(int x, int y) { return (long long)x * y % MOD; }
const int mx = 1e5 + 10;
int n, m;
int xx[] = {0, 1, 0, -1};
int yy[] = {-1, 0, 1, 0};
vector<string> g;
int bfs(int sx, int sy, int tx, int ty) {
  vector<vector<int>> dist(n, vector<int>(m, -1));
  queue<pair<int, int>> q;
  q.push({sx, sy});
  dist[sx][sy] = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int X = x + xx[i];
      int Y = y + yy[i];
      if (0 <= X && X < n && 0 <= Y && Y < m && dist[X][Y] == -1 &&
          g[X][Y] == '.') {
        dist[X][Y] = dist[x][y] + 1;
        q.push({X, Y});
      }
    }
  }
  return dist[tx][ty];
}
void solve() {
  cin >> n >> m;
  g.resize(n);
  int ans = 0;
  for (int i = 0; i < n; i++) cin >> g[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int ii = 0; ii < n; ii++) {
        for (int jj = 0; jj < m; jj++) {
          ans = max(ans, bfs(i, j, ii, jj));
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
