#include <bits/stdc++.h>
using namespace std;
int solve_maze(int start_i, int start_j, int goal_i, int goal_j, int direction,
               vector<vector<char>> map, vector<vector<int>> visit_map,
               int depth) {
  int max_i = map.size();
  int max_j = map[0].size();
  int depth_min = 100000000;
  int depth_ret;
  visit_map[start_i][start_j] = 1;
  if (start_i == goal_i && start_j == goal_j) {
    return depth;
  }
  if (start_i + 1 < max_i && map[start_i + 1][start_j] != '#' &&
      direction != 1 && visit_map[start_i + 1][start_j] == 0) {
    depth_ret = solve_maze(start_i + 1, start_j, goal_i, goal_j, 0, map,
                           visit_map, depth + 1);
    if (depth_ret > 0 && depth_min > depth_ret) {
      depth_min = depth_ret;
    }
  }
  if (start_i - 1 > -1 && map[start_i - 1][start_j] != '#' && direction != 0 &&
      visit_map[start_i - 1][start_j] == 0) {
    depth_ret = solve_maze(start_i - 1, start_j, goal_i, goal_j, 1, map,
                           visit_map, depth + 1);
    if (depth_ret > 0 && depth_min > depth_ret) {
      depth_min = depth_ret;
    }
  }
  if (start_j + 1 < max_j && map[start_i][start_j + 1] != '#' &&
      direction != 3 && visit_map[start_i][start_j + 1] == 0) {
    depth_ret = solve_maze(start_i, start_j + 1, goal_i, goal_j, 2, map,
                           visit_map, depth + 1);
    if (depth_ret > 0 && depth_min > depth_ret) {
      depth_min = depth_ret;
    }
  }
  if (start_j - 1 > -1 && map[start_i][start_j - 1] != '#' && direction != 2 &&
      visit_map[start_i][start_j - 1] == 0) {
    depth_ret = solve_maze(start_i, start_j - 1, goal_i, goal_j, 3, map,
                           visit_map, depth + 1);
    if (depth_ret > 0 && depth_min > depth_ret) {
      depth_min = depth_ret;
    }
  }
  if (depth_min == 100000000) {
    return -1;
  } else {
    return depth_min;
  }
}
int main(void) {
  int ans = 0;
  int h, w;
  cin >> h >> w;
  vector<vector<char>> map(h, vector<char>(w));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> map[i][j];
    }
  }
  vector<vector<int>> visit_map(h, vector<int>(w, 0));
  for (int start_i = 0; start_i < h; ++start_i) {
    for (int start_j = 0; start_j < w; ++start_j) {
      for (int goal_i = 0; goal_i < h; ++goal_i) {
        for (int goal_j = 0; goal_j < w; ++goal_j) {
          ans = max(ans, solve_maze(start_i, start_j, goal_i, goal_j, -1, map,
                                    visit_map, 0));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
