#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
char maze[21][21];
int dist[21][21];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void reset_dist() {
  for (int i = 0; i < (21); ++i)
    for (int j = 0; j < (21); ++j) dist[i][j] = 0;
}
int main() {
  int h, w;
  cin >> h >> w;
  int ans = 0;
  for (int i = 0; i < (21); ++i)
    for (int j = 0; j < (21); ++j) {
      maze[i][j] = '#';
      dist[i][j] = 0;
    }
  for (int i = 0; i < (h); ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < (s.size()); ++j) maze[i + 1][j + 1] = s[j];
  }
  for (int i = 0; i < (21); ++i) {
    for (int j = 0; j < (21); ++j) {
      cout << maze[i][j];
    }
    cout << endl;
  }
  for (int start = 0; start < 400; ++start) {
    for (int goal = start + 1; goal < 400; ++goal) {
      int sx, sy, gx, gy;
      sx = start % 20 + 1;
      sy = (start / 20) % 20 + 1;
      gx = goal % 20 + 1;
      gy = (goal / 20) % 20 + 1;
      if (maze[sy][sx] == '.' && maze[gy][gx] == '.') {
        reset_dist();
        queue<P> Q;
        P p(sy, sx);
        Q.push(p);
        while (1) {
          int x, y;
          P p(0, 0);
          p = Q.front();
          Q.pop();
          x = p.second;
          y = p.first;
          if (y == gy and x == gx) {
            if (ans < dist[gy][gx]) {
              ans = dist[gy][gx];
            }
            break;
          }
          for (int i = 0; i < (4); ++i) {
            if (y + dy[i] > 20 || x + dx[i] > 20) continue;
            if (maze[y + dy[i]][x + dx[i]] == '.') {
              if (dist[y + dy[i]][x + dx[i]] == 0) {
                P cand(0, 0);
                cand.first = y + dy[i];
                cand.second = x + dx[i];
                Q.push(cand);
                dist[y + dy[i]][x + dx[i]] = dist[y][x] + 1;
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
