#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int dx[]{1, -1, 0, 0};
int dy[]{0, 0, 1, -1};
int n;
int m;
char grid[N][N];
int vis[N][N];
int get(int a, int b, int c, int d) {
  queue<pair<pair<int, int>, int> > q;
  q.push({{a, b}, 0});
  memset(vis, 0, sizeof vis);
  while (!q.empty()) {
    int x = q.front().first.first;
    int y = q.front().first.second;
    int dist = q.front().second;
    q.pop();
    if (vis[x][y]) continue;
    if (x == c && y == d) return dist;
    vis[x][y] = 1;
    for (int i = 0; i < 4; i++) {
      int nwx = x + dx[i];
      int nwy = y + dy[i];
      if (nwx >= 1 && nwy >= 1 && nwx <= n && nwy <= m &&
          grid[nwx][nwy] != '#') {
        q.push({{nwx, nwy}, dist + 1});
      }
    }
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  int mx = 0;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= m; b++) {
      for (int c = 1; c <= n; c++) {
        for (int d = 1; d <= m; d++) {
          mx = max(mx, get(a, b, c, d));
        }
      }
    }
  }
  cout << mx << endl;
}
