#include <bits/stdc++.h>
using namespace std;
int maze[22][22] = {0};
int maze_cnt[22][22] = {0};
int h, w;
int bfs(int x, int y, int step) {
  int maxstep = 0;
  int nextstep[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  queue<pair<int, int>> point;
  for (int i = 0; i < (int)(22); i++)
    for (int j = 0; j < (int)(22); j++) {
      maze_cnt[i][j] = 1000000000;
    }
  maze_cnt[x][y] = 0;
  point.push(pair<int, int>(x, y));
  int ans = 0;
  while (!point.empty()) {
    pair<int, int> p = point.front();
    point.pop();
    for (int i = 0; i < 4; i++) {
      pair<int, int> newp =
          pair<int, int>(p.first + nextstep[i][0], p.second + nextstep[i][1]);
      if (newp.first != 0 && newp.first != w + 1 && newp.second != 0 &&
          newp.second != h + 1) {
        if (maze_cnt[newp.first][newp.second] == 1000000000 &&
            maze[newp.first][newp.second] == 0) {
          maze_cnt[newp.first][newp.second] = maze_cnt[p.first][p.second] + 1;
          point.push(newp);
          ans = max(ans, maze_cnt[newp.first][newp.second]);
        }
      }
    }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  for (int y = 0; y < (int)(h); y++)
    for (int x = 0; x < (int)(w); x++) {
      char wall;
      cin >> wall;
      if (wall == '#') {
        maze[x + 1][y + 1] = 1;
      }
    }
  int ans = 0;
  for (int y = 0; y < (int)(h); y++)
    for (int x = 0; x < (int)(w); x++) {
      int maxstep = bfs(x + 1, y + 1, 0);
      ans = max(ans, maxstep);
    }
  cout << ans << endl;
}
