#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char arr[23][23];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  int ans = 0;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < m; b++) {
      for (int c = 0; c < n; c++) {
        for (int d = 0; d < m; d++) {
          if (arr[a][b] == '#' || arr[c][d] == '#') continue;
          bool processed[23][23] = {};
          int ta = 0;
          queue<tuple<int, int, int>> q;
          q.push(make_tuple(a, b, 0));
          while (!q.empty()) {
            int x = get<0>(q.front());
            int y = get<1>(q.front());
            int dis = get<2>(q.front());
            q.pop();
            if (processed[x][y]) continue;
            processed[x][y] = true;
            if (x == c && y == d) {
              ta = dis;
              break;
            }
            if (x + 1 < m && arr[x + 1][y] == '.')
              q.push(make_tuple(x + 1, y, dis + 1));
            if (x - 1 >= 0 && arr[x - 1][y] == '.')
              q.push(make_tuple(x - 1, y, dis + 1));
            if (y + 1 < n && arr[x][y + 1] == '.')
              q.push(make_tuple(x, y + 1, dis + 1));
            if (y - 1 >= 0 && arr[x][y - 1] == '.')
              q.push(make_tuple(x, y - 1, dis + 1));
          }
          ans = max(ans, ta);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
