#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
vector<long long> g[N];
long long h, w, ans = 0;
long long corr = 0, penal = 0;
long long dx[] = {1, 0, 0, -1};
long long dy[] = {0, 1, -1, 0};
long long level[25][25];
bool vis[25][25];
char arena[25][25];
bool is_valid(long long x, long long y) {
  if (arena[x][y] == '#' || (x >= h) || x < 0 || y >= w || y < 0) return false;
  return true;
}
long long bfs(long long x, long long y) {
  long long last_x, last_y;
  queue<pair<long long, long long>> q;
  q.push({x, y});
  level[x][y] = 0;
  vis[x][y] = 1;
  while (!q.empty()) {
    auto curr = q.front();
    q.pop();
    long long currX = curr.first;
    long long currY = curr.second;
    for (long long i = 0; i < 4; i++) {
      long long newX = currX + dx[i];
      long long newY = currY + dy[i];
      if (is_valid(newX, newY) && !vis[newX][newY]) {
        q.push({newX, newY});
        level[newX][newY] = level[currX][currY] + 1;
        vis[newX][newY] = 1;
        last_x = newX;
        last_y = newY;
      }
    }
  }
  return level[last_x][last_y];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> h >> w;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) cin >> arena[i][j];
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      memset(level, 0, sizeof(level));
      memset(vis, false, sizeof(vis));
      ans = max(ans, bfs(i, j));
    }
  }
  cout << ans << "\n";
  return 0;
}
