#include <bits/stdc++.h>
using namespace std;
int H, W, an;
int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1};
vector<string> maze;
void bfs(int r, int c) {
  set<pair<int, int>> s;
  queue<tuple<int, int, int>> q;
  s.insert({r, c});
  q.push({r, c, 0});
  int d;
  while (q.size()) {
    tie(r, c, d) = q.front();
    q.pop();
    for (int i = 0; i < 4; ++i) {
      int x = r + dr[i], y = c + dc[i];
      if (x < 0 || y < 0 || x >= H || y >= W || maze[x][y] == '#' ||
          s.count({x, y}))
        continue;
      s.insert({x, y});
      q.push({x, y, d + 1});
    }
  }
  an = max(an, d);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  maze.resize(H);
  for (string &s : maze) cin >> s;
  for (int r = 0; r < H; ++r)
    for (int c = 0; c < W; ++c)
      if (maze[r][c] == '.') {
        bfs(r, c);
      }
  cout << an << '\n';
  return 0;
}
