#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int h, w;
using graph = vector<string>;
vector<string> maze(h);
vector<vector<bool>> seen;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int solve(const graph &maze, int i, int j, int gi, int gj) {
  if (maze[i][j] == '#') return 0;
  if (maze[gi][gj] == '#') return 0;
  queue<P> q;
  q.push(make_pair(w * i + j, 0));
  while (q.size()) {
    int y = q.front().first / w;
    int x = q.front().first % w;
    seen[y][x] = true;
    int dist = q.front().second;
    q.pop();
    for (int l = 0; l < 4; l++) {
      int ny = y + dy[l];
      int nx = x + dx[l];
      if (nx == gj && ny == gi) return dist + 1;
      if (ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
      if (maze[ny][nx] == '#' || seen[ny][nx]) continue;
      q.push(make_pair(w * ny + nx, dist + 1));
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  maze.assign(h, "");
  seen.assign(h, vector<bool>(w, false));
  vector<vector<bool>> cseen;
  cseen = seen;
  for (int i = 0; i < (h); ++i) cin >> maze[i];
  int M = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      for (int k = 0; k < (h); ++k)
        for (int l = 0; l < (w); ++l) {
          if (i == k && j == l) continue;
          M = max(M, solve(maze, i, j, k, l));
          seen = cseen;
        }
    }
  cout << M << endl;
}
