#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long maxn = 1e6 + 5;
long long h, w;
char e[30][30];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int bfs(int x, int y) {
  int dis[30][30] = {0};
  int vis[30][30] = {0};
  queue<pair<int, int> > q;
  q.push({x, y});
  dis[x][y] = 0;
  while (!q.empty()) {
    pair<int, int> top = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int tx = top.first + dx[i];
      int ty = top.second + dy[i];
      if (tx > 0 && tx <= h && ty > 0 && ty <= w && e[tx][ty] == '.' &&
          vis[tx][ty] == 0) {
        dis[tx][ty] = dis[top.first][top.second] + 1, vis[tx][ty] = 1;
        q.push({tx, ty});
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      ans = max(ans, dis[i][j]);
    }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> e[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (e[i][j] == '.') ans = max(ans, bfs(i, j));
    }
  }
  cout << ans;
  return 0;
}
