#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> maze(h);
  for (int i = 0; i < h; ++i) {
    cin >> maze[i];
  }
  int mx = 0;
  int movei[] = {1, 0, -1, 0};
  int movej[] = {0, 1, 0, -1};
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      vector<vector<int>> d(h, vector<int>(w, -1));
      d[i][j] = 0;
      queue<pair<int, int>> q;
      q.emplace(i, j);
      while (!q.empty()) {
        int ii = q.front().first;
        int jj = q.front().second;
        q.pop();
        for (int move = 0; move < 4; ++move) {
          int iii = ii + movei[move];
          int jjj = jj + movej[move];
          if (iii < 0 || jjj < 0 || iii >= h || jjj >= w ||
              maze[iii][jjj] != '.' || d[iii][jjj] != -1)
            continue;
          d[iii][jjj] = d[ii][jj] + 1;
          q.emplace(iii, jjj);
        }
      }
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) {
          if (d[k][l] > mx) mx = d[k][l];
        }
      }
    }
  }
  cout << mx << endl;
}
