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