#include <bits/stdc++.h>
using namespace std;
long long H, W;
vector<vector<char>> S;
vector<vector<long long>> C;
void solve() {
  cin >> H >> W;
  S = vector<vector<char>>(H, vector<char>(W));
  C = vector<vector<long long>>(H, vector<long long>(W, -1));
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<pair<long long, long long>> delta = {
      make_pair(0, 1), make_pair(1, 0), make_pair(0, -1), make_pair(-1, 0)};
  long long maxCost = 0;
  for (long long gx = 0; gx < H; gx++) {
    for (long long gy = 0; gy < W; gy++) {
      if (S.at(gx).at(gy) == '#') {
        continue;
      }
      C = vector<vector<long long>>(H, vector<long long>(W, -1));
      queue<vector<pair<long long, long long>>> que;
      long long cost = 0;
      vector<pair<long long, long long>> vec;
      que.push(vec);
      que.front().push_back(make_pair(gx, gy));
      bool isStart = false;
      while (!que.empty()) {
        vector<pair<long long, long long>> fr = que.front();
        que.pop();
        vector<pair<long long, long long>> vec;
        for (auto afr : fr) {
          long long nx = afr.first;
          long long ny = afr.second;
          C.at(nx).at(ny) = cost;
          for (long long ix = 0; ix < 4; ix++) {
            long long dx = nx + delta.at(ix).first;
            long long dy = ny + delta.at(ix).second;
            if (0 <= dx && dx < H && 0 <= dy && dy < W) {
              char s = S.at(dx).at(dy);
              if (s != '#' && C.at(dx).at(dy) == -1) {
                vec.push_back(make_pair(dx, dy));
              }
            }
          }
        }
        if (vec.size() > 0) {
          que.push(vec);
          cost++;
        }
      }
      maxCost = max(maxCost, cost);
    }
  }
  cout << maxCost << endl;
  return;
}
int main() {
  solve();
  return 0;
}
