#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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[i][j];
    }
  }
  int max = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        continue;
      }
      priority_queue<pair<int, pair<int, int> >,
                     vector<pair<int, pair<int, int> > >,
                     greater<pair<int, pair<int, int> > > >
          q;
      vector<vector<int> > map(H, vector<int>(W, 0));
      q.push(make_pair(0, make_pair(i, j)));
      int num = 0;
      while (!q.empty()) {
        pair<int, pair<int, int> > Q = q.top();
        num = Q.first;
        pair<int, int> pos = Q.second;
        q.pop();
        if (pos.first != 0) {
          if (S[pos.first - 1][pos.second] == '.') {
            if (map[pos.first - 1][pos.second] == 0) {
              map[pos.first - 1][pos.second] = num + 1;
              q.push(make_pair(num + 1, make_pair(pos.first - 1, pos.second)));
            }
          }
        }
        if (pos.first != H - 1) {
          if (S[pos.first + 1][pos.second] == '.') {
            if (map[pos.first + 1][pos.second] == 0) {
              map[pos.first + 1][pos.second] = num + 1;
              q.push(make_pair(num + 1, make_pair(pos.first + 1, pos.second)));
            }
          }
        }
        if (pos.second != 0) {
          if (S[pos.first][pos.second - 1] == '.') {
            if (map[pos.first][pos.second - 1] == 0) {
              map[pos.first][pos.second - 1] = num + 1;
              q.push(make_pair(num + 1, make_pair(pos.first, pos.second - 1)));
            }
          }
        }
        if (pos.second != W - 1) {
          if (S[pos.first][pos.second + 1] == '.') {
            if (map[pos.first][pos.second + 1] == 0) {
              map[pos.first][pos.second + 1] = num + 1;
              q.push(make_pair(num + 1, make_pair(pos.first, pos.second + 1)));
            }
          }
        }
        if (num > max) {
          max = num;
        }
      }
    }
  }
  cout << max << endl;
}
