#include <bits/stdc++.h>
using namespace std;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int dist[25][25], grid[25][25], vis[25][25];
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int n, m;
int bfs(int sx, int sy) {
  memset(vis, 0, sizeof(vis));
  vis[sx][sy] = 1;
  dist[sx][sy] = 0;
  int maxDist = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(sx, sy));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int tx = u.first + fx[i];
      int ty = u.second + fy[i];
      if (tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] &&
          grid[tx][ty] != -1) {
        vis[tx][ty] = 1;
        dist[tx][ty] = dist[u.first][u.second] + 1;
        maxDist = max(maxDist, dist[tx][ty]);
        q.push(make_pair(tx, ty));
      }
    }
  }
  return maxDist;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < m; j++) {
      if (str[j] == '#') grid[i][j] = -1;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
