#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input() {}
char grid[21][21];
int dist[21][21];
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int get_distance(int i, int j) {
  queue<pair<pair<int, int>, int>> que;
  que.push(make_pair(make_pair(i, j), 0));
  bool vis[21][21];
  int dis = 0;
  memset(vis, false, sizeof vis);
  while (!que.empty()) {
    pair<pair<int, int>, int> p = que.front();
    que.pop();
    dis = max(dis, p.second);
    vis[p.first.first][p.first.second] = 1;
    for (int x = 0; x < 4; x++) {
      int newx = p.first.first + dx[x];
      int newy = p.first.second + dy[x];
      int d = p.second;
      if (newx >= 0 && newx < n && newy >= 0 && newy < m &&
          grid[newx][newy] != '#' && !vis[newx][newy]) {
        que.push(make_pair(make_pair(newx, newy), d + 1));
      }
    }
  }
  return dis;
}
int main() {
  fastio();
  int i, j, k, l, ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  memset(dist, -1, sizeof dist);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (dist[i][j] == -1 && dist[j][i] == -1) {
        int dis = get_distance(i, j);
        ans = max(ans, dis);
      }
    }
  }
  cout << ans;
  return 0;
}
