#include <bits/stdc++.h>
using namespace std;
int n, m;
int cost[25][25];
bool vis[25][25];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
string a[25];
bool valid(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && a[x][y] != '#' && !vis[x][y];
}
void bfs(int u, int v) {
  queue<pair<int, int> > q;
  q.push({u, v});
  vis[u][v] = true;
  cost[u][v] = 0;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int i, j, x, y, xx, yy;
    x = p.first, y = p.second;
    for (i = 0; i < 4; i++) {
      xx = x + dx[i];
      yy = y + dy[i];
      if (valid(xx, yy)) {
        vis[xx][yy] = true;
        cost[xx][yy] = cost[x][y] + 1;
        q.push({xx, yy});
      }
    }
  }
}
int main() {
  cin >> n >> m;
  int i, j;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] != '#') {
        bfs(i, j);
        break;
      }
    }
  }
  int ans = -1;
  pair<int, int> p;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] != '#') {
        if (ans < cost[i][j]) {
          ans = cost[i][j];
          p = {i, j};
        }
      }
    }
  }
  memset(vis, false, sizeof(vis));
  memset(cost, 0, sizeof(cost));
  bfs(p.first, p.second);
  ans = -1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] != '#') {
        if (ans < cost[i][j]) {
          ans = cost[i][j];
        }
      }
    }
  }
  cout << ans;
}
