#include <bits/stdc++.h>
using namespace std;
const vector<vector<int>> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const long long MOD = 1000000007;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T>
int dp2csv(const vector<vector<T>>& dp, const string fname);
int range_check(int val, int min, int max) {
  if (val < min) {
    return -1;
  }
  if (val > max) {
    return -1;
  }
  return val;
}
template <class T, class T1>
bool array_find(const T& array, const T1& dst) {
  auto result = find(array.first(), array.end(), dst);
  if (result == array.end()) {
    return false;
  } else {
    return true;
  }
}
class qi {
 public:
  qi(int h, int w, int cost) : h(h), w(w), cost(cost){};
  int h, w, cost;
};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> field(h, vector<int>(w, -1));
  for (int hh = 0; hh < h; hh++) {
    string str;
    cin >> str;
    for (int ww = 0; ww < w; ww++) {
      if (str[ww] == '.') {
        field[hh][ww] = 0;
      } else {
        field[hh][ww] = -1;
      }
    }
  }
  int all_max = 0;
  for (int hh = 0; hh < h; hh++) {
    for (int ww = 0; ww < w; ww++) {
      if (field[hh][ww] == -1) continue;
      vector<vector<int>> now_field = field;
      int now_max = 0;
      deque<qi> deq;
      deq.push_back(qi(hh, ww, 1));
      while (deq.size() > 0) {
        qi nowqi = deq.front();
        deq.pop_front();
        now_field[nowqi.h][nowqi.w] = nowqi.cost;
        for (int i = 0; i < 4; i++) {
          int next_h = nowqi.h + DIR[i][0], next_w = nowqi.w + DIR[i][1];
          if (range_check(next_h, 0, h - 1) != -1 &&
              range_check(next_w, 0, w - 1) != -1) {
            if (now_field[next_h][next_w] == 0) {
              deq.push_back(qi(next_h, next_w, nowqi.cost + 1));
              now_max = max(nowqi.cost + 1, now_max);
            }
          }
        }
      }
      all_max = max(now_max, all_max);
    }
  }
  cout << all_max - 1 << endl;
  return 0;
}
template <class T>
int dp2csv(const vector<vector<T>>& dp, const string fname) {
  ofstream ofs(fname);
  if (ofs.fail()) {
    cerr << "cannot open file. :" + fname << endl;
    return -1;
  }
  for (auto dp_row : dp) {
    for (auto dp_cell : dp_row) {
      ofs << dp_cell << ",";
    }
    ofs << endl;
  }
  ofs.close();
  return 0;
}
