#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> S(h, vector<char>(w));
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      cin >> S[i][j];
    }
  }
  vector<vector<int>> dis(h, vector<int>(w, -1));
  int max = 0;
  int Sy, Sx, Gy, Gx;
  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      for (int i = 0; i < (int)(h); i++) {
        for (int j = 0; j < (int)(w); j++) {
          dis[i][j] = -1;
        }
      }
      dis[sy][sx] = 0;
      queue<pair<int, int>> q;
      q.push(make_pair(sy, sx));
      int dx[4] = {0, 1, 0, -1};
      int dy[4] = {1, 0, -1, 0};
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
          int ny = p.first + dy[i];
          int nx = p.second + dx[i];
          if (nx < 0 || ny < 0 || nx >= w || ny >= h) {
            continue;
          } else if (S[ny][nx] == '#') {
            continue;
          } else if (dis[ny][nx] != -1) {
            continue;
          } else {
            dis[ny][nx] = dis[p.first][p.second] + 1;
            if (dis[ny][nx] > max) {
              max = dis[ny][nx];
              Sy = sy, Sx = sx, Gy = ny, Gx = nx;
            }
            q.push(make_pair(ny, nx));
          }
        }
      }
    }
  }
  cout << max << endl;
}
