#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int p = 0; p < H; p++) {
        for (int q = 0; q < W; q++) {
          if (i != p && j != q) {
            vector<vector<int>> move(H, vector<int>(W, pow(10, 6)));
            for (int r = 0; r < H; r++) {
              for (int s = 0; s < W; s++) {
                if (S.at(r).at(s) == '#') move.at(r).at(s) = -1;
              }
            }
            move.at(i).at(j) = 0;
            queue<vector<int>> Que;
            Que.push({i, j});
            while (Que.size() > 0) {
              int r = Que.front().at(0), s = Que.front().at(1);
              Que.pop();
              if (r < H - 1) {
                if (move.at(r + 1).at(s) > 1 + move.at(r).at(s)) {
                  move.at(r + 1).at(s) = 1 + move.at(r).at(s);
                  Que.push({r + 1, s});
                }
              }
              if (s < W - 1) {
                if (move.at(r).at(s + 1) > 1 + move.at(r).at(s)) {
                  move.at(r).at(s + 1) = 1 + move.at(r).at(s);
                  Que.push({r, s + 1});
                }
              }
              if (0 < r) {
                if (move.at(r - 1).at(s) > 1 + move.at(r).at(s)) {
                  move.at(r - 1).at(s) = 1 + move.at(r).at(s);
                  Que.push({r - 1, s});
                }
              }
              if (0 < s) {
                if (move.at(r).at(s - 1) > 1 + move.at(r).at(s)) {
                  move.at(r).at(s - 1) = 1 + move.at(r).at(s);
                  Que.push({r, s - 1});
                }
              }
            }
            ans = max(ans, move.at(p).at(q));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
