#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int> > board(h, vector<int>(w, 1));
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      char s;
      cin >> s;
      if (s == '#') board[y][x] = 0;
    }
  }
  int far = 0;
  vector<int> movex{0, 0, 1, -1};
  vector<int> movey{1, -1, 0, 0};
  for (int a = 0; a < h; a++) {
    for (int b = 0; b < w; b++) {
      if (!board[a][b]) continue;
      vector<vector<int> > checked(h, vector<int>(w, 0));
      queue<vector<int> > que;
      que.push({a, b});
      while (!que.empty()) {
        vector<int> pos = que.front();
        que.pop();
        int posx = pos[1], posy = pos[0];
        far = far < checked[posy][posx] ? checked[posy][posx] : far;
        for (int j = 0; j < 4; j++) {
          int x = posx + movex[j];
          int y = posy + movey[j];
          if (x >= 0 && x < w && y >= 0 && y < h && board[y][x] &&
              !checked[y][x]) {
            que.push({y, x});
            checked[y][x] = checked[posy][posx] + 1;
          }
        }
      }
    }
  }
  cout << far << endl;
}
