#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> s(h, vector<bool>(w));
  for (int y = 0; y < (h); ++y) {
    for (int x = 0; x < (w); ++x) {
      char c;
      cin >> c;
      s.at(y).at(x) = c == '#';
    }
  }
  int res(0);
  for (int y = 0; y < (h); ++y) {
    for (int x = 0; x < (w); ++x) {
      if (s.at(y).at(x)) continue;
      p start = make_pair(x, y);
      for (int y2 = 0; y2 < (h); ++y2) {
        for (int x2 = 0; x2 < (w); ++x2) {
          if (s.at(y2).at(x2)) continue;
          p end = make_pair(x2, y2);
          int ln(0);
          map<p, int> dist;
          dist[start] = 0;
          queue<p> q;
          q.push(start);
          while (!q.empty()) {
            p f = q.front();
            q.pop();
            int dis = dist[f];
            if (f == end) {
              ln = dis;
              break;
            }
            for (int i = 0; i < (4); ++i) {
              static int dx[4] = {0, 1, 0, -1};
              static int dy[4] = {-1, 0, 1, 0};
              p next = f;
              next.first += dx[i];
              next.second += dy[i];
              if (next.first < 0 || next.first >= w || next.second < 0 ||
                  next.second >= h || s.at(next.second).at(next.first) ||
                  dist.count(next))
                continue;
              dist[next] = dis + 1;
              q.push(next);
            }
          }
          res = max(res, ln);
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
