#include <bits/stdc++.h>
using namespace std;
int h, w;
char board[22][22];
bool visited[22][22];
int dist[22][22];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool check(int i, int j) {
  return (i >= 0) && (i < h) && (j >= 0) && (j < w) && (board[i][j] == '.');
}
int bfs(int sx, int sy) {
  for (int k = 0; k < h; k++) {
    for (int l = 0; l < w; l++) {
      dist[k][l] = 10000;
      visited[k][l] = false;
    }
  }
  int ans = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  dist[sx][sy] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    visited[x][y] = true;
    for (int m = 0; m < 4; m++) {
      int nx = x + dx[m];
      int ny = y + dy[m];
      if (!check(nx, ny)) continue;
      if (visited[nx][ny]) continue;
      dist[nx][ny] = dist[x][y] + 1;
      ans = max(ans, dist[nx][ny]);
      que.push(pair<int, int>(nx, ny));
    }
  }
  return ans;
}
int main(void) {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> board[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') continue;
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << endl;
  return 0;
}
