#include <bits/stdc++.h>
using namespace std;
template <typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template <typename T>
inline T mod(T n, T mod) {
  T res = n % mod;
  if (res < 0) res += mod;
  return res;
}
int vx[] = {0, 0, -1, 1};
int vy[] = {1, -1, 0, 0};
int dist[25][25];
bool vis[25][25];
char grid[25][25];
int n, m;
int bfs(int sti, int stj) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dist[i][j] = 0;
      vis[i][j] = false;
    }
  }
  queue<pair<int, int> > q;
  q.emplace(sti, stj);
  vis[sti][stj] = true;
  dist[sti][stj] = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + vx[i];
      int ny = y + vy[i];
      if (nx >= 0 and nx < n and ny >= 0 and ny < m) {
        if (!vis[nx][ny] and grid[nx][ny] == '.') {
          q.emplace(nx, ny);
          dist[nx][ny] = dist[x][y] + 1;
          vis[nx][ny] = true;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  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;
}
