#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) {
    cin >> grid[i];
  }
  vector<pair<pair<int, int>, pair<int, int>>> sg;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      int sx = i;
      int sy = j;
      for (int k = 0; k < w; k++) {
        for (int l = 0; l < h; l++) {
          int gx = k;
          int gy = l;
          if (grid[sy][sx] == '.' && grid[gy][gx] == '.')
            sg.push_back(make_pair(make_pair(sy, sx), make_pair(gy, gx)));
        }
      }
    }
  }
  int ans = 0;
  for (auto p : sg) {
    queue<pair<int, pair<int, int>>> que;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    int sy = p.first.first;
    int sx = p.first.second;
    int gy = p.second.first;
    int gx = p.second.second;
    int cnt = 0;
    que.push(make_pair(0, make_pair(sy, sx)));
    dist[sy][sx] = 0;
    while (que.size()) {
      pair<int, pair<int, int>> now = que.front();
      que.pop();
      int d = now.first;
      int now_y = now.second.first;
      int now_x = now.second.second;
      if (now_x == gx && now_y == gy) {
        ans = max(ans, d);
        break;
      }
      int dy[4] = {0, 1, 0, -1};
      int dx[4] = {1, 0, -1, 0};
      for (int i = 0; i < 4; i++) {
        int ny = now_y + dy[i];
        int nx = now_x + dx[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && dist[ny][nx] == -1 &&
            grid[ny][nx] == '.') {
          que.push(make_pair(d + 1, make_pair(ny, nx)));
        }
      }
    }
  }
  cout << ans << endl;
}
