#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int R, C;
vector<string> a;
queue<int> rq, cq;
vector<int> dr{-1, 1, 0, 0};
vector<int> dc{0, 0, 1, -1};
int nodes_in_next_layer = 0, nodes_left_in_layer = 1;
void explore_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 (visited[rr][cc]) continue;
    if (a[rr][cc] == '#') continue;
    rq.push(rr);
    cq.push(cc);
    visited[rr][cc] = true;
    nodes_in_next_layer++;
  }
}
int try_maze(int i, int j, int i1, int j1) {
  nodes_left_in_layer = 1;
  nodes_in_next_layer = 0;
  vector<vector<bool>> visited(R, vector<bool>(C));
  int move_count = 0;
  bool reached_end = false;
  a[i1][j1] = 'E';
  visited[i][j] = true;
  rq.push(i);
  cq.push(j);
  while (rq.size() > 0) {
    int r = rq.front();
    rq.pop();
    int c = cq.front();
    cq.pop();
    if (a[r][c] == 'E') {
      reached_end = true;
      break;
    }
    explore_neighbours(r, c, visited);
    nodes_left_in_layer--;
    if (nodes_left_in_layer == 0) {
      nodes_left_in_layer = nodes_in_next_layer;
      nodes_in_next_layer = 0;
      move_count++;
    }
  }
  while (rq.size() > 0) {
    rq.pop();
    cq.pop();
  }
  a[i1][j1] = '.';
  if (reached_end) return move_count;
  return -1;
}
int main() {
  cin >> R >> C;
  for (int i = 0; i < R; i++) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  int mx = 0;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      for (int i1 = 0; i1 < R; i1++) {
        for (int j1 = 0; j1 < C; j1++) {
          if (i == i1 && j == j1) continue;
          if (a[i][j] != '#' && a[i1][j1] != '#') {
            mx = max(mx, try_maze(i, j, i1, j1));
          }
        }
      }
    }
  }
  cout << mx;
  return 0;
}
