#include <bits/stdc++.h>
using namespace std;
int H, W;
vector<string> maze;
int bfs(int s1, int s2, int e1, int e2) {
  int ans = 0;
  bool visited[22][22] = {};
  queue<pair<int, int> > q1;
  q1.push(make_pair(s1, s2));
  visited[s1][s2] = true;
  bool found = false;
  while (!found) {
    queue<pair<int, int> > q2;
    while (!q1.empty()) {
      pair<int, int> v = q1.front();
      q1.pop();
      int x = v.first;
      int y = v.second;
      if (x == e1 && y == e2) {
        found = true;
        break;
      }
      for (int dx = -1; dx < 2; ++dx)
        for (int dy = -1; dy < 2; ++dy) {
          if (abs(dx - dy) != 1) continue;
          int nx = x + dx;
          int ny = y + dy;
          if (nx < 0 || nx > H - 1 || ny < 0 || ny > W - 1) continue;
          if (visited[nx][ny] || maze[nx][ny] == '#') continue;
          q2.push(make_pair(nx, ny));
        }
    }
    q1 = q2;
    ans++;
  }
  return --ans;
}
int main() {
  cin >> H >> W;
  string tmp;
  for (int i = 0; i < (H); ++i) {
    cin >> tmp;
    maze.push_back(tmp);
  }
  int ans = 0;
  for (int s1 = 0; s1 < H; ++s1)
    for (int s2 = 0; s2 < W; ++s2)
      for (int e1 = 0; e1 < H; ++e1)
        for (int e2 = 0; e2 < W; ++e2) {
          if (maze[s1][s2] == '.' && maze[e1][e2] == '.')
            ans = max(ans, bfs(s1, s2, e1, e2));
        }
  cout << ans << endl;
  return 0;
}
