#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      cin >> maze[y][x];
    }
  }
  vector<vector<vector<vector<int>>>> graph(
      H, vector<vector<vector<int>>>(
             W, vector<vector<int>>(H, vector<int>(W, INT_MAX / 4))));
  auto connect = [&](int x, int y, int x2, int y2) {
    graph[y2 - 1][x2 - 1][y - 1][x - 1] = 1;
    graph[y - 1][x - 1][y2 - 1][x2 - 1] = 1;
  };
  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      graph[y - 1][x - 1][y - 1][x - 1] = 0;
      if (maze[y][x] == '.') {
        if (maze[y][x - 1] == '.') connect(x, y, x - 1, y);
        if (maze[y][x + 1] == '.') connect(x, y, x + 1, y);
        if (maze[y - 1][x] == '.') connect(x, y, x, y - 1);
        if (maze[y + 1][x] == '.') connect(x, y, x, y + 1);
      }
    }
  }
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      for (int y2 = 0; y2 < H; ++y2) {
        for (int x2 = 0; x2 < W; ++x2) {
          for (int y3 = 0; y3 < H; ++y3) {
            for (int x3 = 0; x3 < W; ++x3) {
              graph[y][x][y3][x3] = graph[y3][x3][y][x] =
                  min(graph[y][x][y3][x3],
                      graph[y][x][y2][x2] + graph[y2][x2][y3][x3]);
            }
          }
        }
      }
    }
  }
  int maxpath = 0;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      for (int y2 = 0; y2 < H; ++y2) {
        for (int x2 = 0; x2 < W; ++x2) {
          int p = graph[y][x][y2][x2];
          if (p != INT_MAX / 4) maxpath = max(p, maxpath);
        }
      }
    }
  }
  cout << maxpath << '\n';
}
