#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<int> vx = {1, -1, 0, 0};
vector<int> vy = {0, 0, 1, -1};
int main() {
  long long h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  long long maxv = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      long long tmp = 0;
      pair<long long, long long> startpos = make_pair(i, j);
      queue<pair<pair<long long, long long>, long long>> q;
      vector<vector<long long>> tmpv(h, vector<long long>(w, mod));
      if (s[i][j] != '#') {
        q.push(make_pair(startpos, 0));
      }
      while (q.size() > 0) {
        pair<long long, long long> curpos = q.front().first;
        long long curv = q.front().second;
        q.pop();
        tmpv[curpos.first][curpos.second] =
            min(tmpv[curpos.first][curpos.second], curv);
        for (int k = 0; k < 4; ++k) {
          long long nextx = curpos.second + vx[k];
          long long nexty = curpos.first + vy[k];
          if (nexty < h && nexty >= 0 && nextx < w && nextx >= 0 &&
              s[nexty][nextx] != '#' && tmpv[nexty][nextx] == mod) {
            q.push(
                make_pair(pair<long long, long long>(nexty, nextx), curv + 1));
          }
        }
      }
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) {
          if (tmpv[k][l] != mod) {
            maxv = max(maxv, tmpv[k][l]);
          }
        }
      }
    }
  }
  cout << maxv << endl;
  return 0;
}
