#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char C[H][W];
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      char tmp;
      cin >> tmp;
      C[i][j] = tmp;
    }
  }
  int distance[H][W];
  queue<pair<int, int> > q;
  int dy[4] = {1, 0, -1, 0};
  int dx[4] = {0, 1, 0, -1};
  int MAXdis = 0;
  for (int sx = 0; sx < (int)(H); sx++) {
    for (int sy = 0; sy < (int)(W); sy++) {
      if (C[sx][sy] == '#') continue;
      for (int gx = 0; gx < (int)(H); gx++) {
        for (int gy = 0; gy < (int)(W); gy++) {
          if (C[gx][gy] == '#') continue;
          if ((sx == gx) && (sy == gy)) continue;
          int dismax = 0;
          fill(distance[0], distance[H], 10000);
          q.emplace(sx, sy);
          distance[sx][sy] = 0;
          while (!q.empty()) {
            pair<int, int> now = q.front();
            q.pop();
            for (int i = 0; i < (int)(4); i++) {
              int ny = now.first + dy[i], nx = now.second + dx[i];
              if (0 <= ny && ny <= H && 0 <= nx && nx <= W &&
                  C[ny][nx] != '#' && distance[ny][nx] == 10000) {
                q.emplace(ny, nx);
                distance[ny][nx] = distance[now.first][now.second] + 1;
                dismax = distance[ny][nx];
              }
            }
          }
          MAXdis = max(MAXdis, dismax);
        }
      }
    }
  }
  cout << MAXdis << endl;
  return 0;
}
