#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H, W;
string Maze[20];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
struct Po {
  int y, x, dis;
};
int walk(int sh, int sw) {
  if (Maze[sh][sw] == '#') return 0;
  Po po{sh, sw, 0};
  queue<Po> q;
  q.push(po);
  int memo[H][W];
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      memo[i][j] = 0;
    }
  }
  int dis = 0;
  while (!q.empty()) {
    Po p = q.front();
    q.pop();
    dis = max(dis, p.dis);
    for (int i = 0; i < 4; ++i) {
      int ny = p.y + dy[i];
      int nx = p.x + dx[i];
      if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
      if (memo[ny][nx] == 1) continue;
      if (Maze[ny][nx] == '#') continue;
      memo[ny][nx] = 1;
      Po npo{ny, nx, p.dis + 1};
      q.push(npo);
    }
  }
  return dis;
}
void solve() {
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> Maze[i];
  }
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans = max(ans, walk(i, j));
    }
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
