#include <bits/stdc++.h>
using namespace std;
int h, w, sx, sy, ex, ey, x, y, mx;
string s;
char grid[25][25];
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dist[25][25];
queue<pair<int, int> > q;
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s;
    for (int j = 0; j < w; j++) {
      grid[i][j] = s[j];
    }
  }
  for (int sx = 0; sx < h; sx++) {
    for (int sy = 0; sy < w; sy++) {
      for (int ex = 0; ex < h; ex++) {
        for (int ey = 0; ey < w; ey++) {
          memset(dist, -1, sizeof(dist));
          dist[sx][sy] = 0;
          q.push(make_pair(sx, sy));
          while (!q.empty()) {
            x = q.front().first;
            y = q.front().second;
            q.pop();
            for (int z = 0; z < 4; z++) {
              int nx = x + dx[z], ny = y + dy[z];
              if (nx < 0 || ny < 0) continue;
              if (nx >= h || ny >= w) continue;
              if (dist[nx][ny] != -1) continue;
              if (grid[nx][ny] == '#') continue;
              dist[nx][ny] = dist[x][y] + 1;
              q.push(make_pair(nx, ny));
            }
          }
          if (dist[ex][ey] > mx) {
            mx = dist[ex][ey];
          }
        }
      }
    }
  }
  cout << mx;
}
