#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int H, W, r = 0;
  cin >> H >> W;
  vector<string> f(H);
  set<pair<int, int>> seen;
  for (int i = 0; i < (H); ++i) cin >> f.at(i);
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      int tr = 0;
      vector<vector<int>> d(H, vector<int>(W, INF));
      queue<pair<int, int>> q;
      q.push(pair<int, int>(i, j));
      d.at(i).at(j) = 0;
      while (!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        for (int k = 0; k < (4); ++k) {
          int nh = p.first + dx[k], nw = p.second + dy[k];
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (f.at(nh).at(nw) != '#' && d.at(nh).at(nw) == INF) {
            q.push(pair<int, int>(nh, nw));
            d.at(nh).at(nw) = d.at(p.first).at(p.second) + 1;
          }
        }
      }
      for (int k = 0; k < (H); ++k)
        for (int l = 0; l < (W); ++l)
          if (d.at(k).at(l) != INF) tr = max(tr, d.at(k).at(l));
      r = max(r, tr);
    }
  cout << r << endl;
}
