#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int R, C;
vector<string> m;
queue<pair<int, int>> P;
vector<int> dr{-1, 1, 0, 0}, dc{0, 0, 1, -1};
int nodesLeft, nextNodes;
void find_neighbours(int r, int c, vector<vector<bool>> &visited) {
  for (int i = 0; i < 4; i++) {
    int rr = r + dr[i];
    int cc = c + dc[i];
    if (rr < 0 || cc < 0) continue;
    if (rr >= R || cc >= C) continue;
    if (m[rr][cc] == '#') continue;
    if (visited[rr][cc]) continue;
    P.push(make_pair(rr, cc));
    visited[rr][cc] = true;
    nextNodes++;
  }
}
int bfs(int i, int j) {
  P.push(make_pair(i, j));
  vector<vector<bool>> visited(R, vector<bool>(C));
  nodesLeft = 1;
  nextNodes = 0;
  int moves = 0;
  while (!P.empty()) {
    pair<int, int> p = P.front();
    P.pop();
    int x = p.first;
    int y = p.second;
    find_neighbours(x, y, visited);
    nodesLeft--;
    if (nodesLeft == 0) {
      nodesLeft = nextNodes;
      nextNodes = 0;
      moves++;
    }
  }
  return moves;
}
int main() {
  cin >> R >> C;
  for (int i = 0; i < R; i++) {
    string s;
    cin >> s;
    m.push_back(s);
  }
  int mx = 0;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      if (m[i][j] == '.') mx = max(mx, bfs(i, j));
    }
  }
  cout << mx - 1 << endl;
  return 0;
}
