#include <bits/stdc++.h>
using namespace std;
int tansaku(vector<vector<char>> &chizu, vector<vector<bool>> check, int X,
            int Y, int count, int H, int W, vector<vector<int>> &B) {
  check.at(X).at(Y) = true;
  B.at(X).at(Y) = min(B.at(X).at(Y), count);
  int ans;
  if (B.at(X).at(Y) > count) {
    B.at(X).at(Y) = count;
    ans = count;
  } else {
    ans = B.at(X).at(Y);
  }
  if (X - 1 >= 0 && !check.at(X - 1).at(Y) && chizu.at(X - 1).at(Y) == '.') {
    ans = max(tansaku(chizu, check, X - 1, Y, count + 1, H, W, B), ans);
  }
  if (Y - 1 >= 0 && !check.at(X).at(Y - 1) && chizu.at(X).at(Y - 1) == '.') {
    ans = max(tansaku(chizu, check, X, Y - 1, count + 1, H, W, B), ans);
  }
  if (X + 1 < H && !check.at(X + 1).at(Y) && chizu.at(X + 1).at(Y) == '.') {
    ans = max(tansaku(chizu, check, X + 1, Y, count + 1, H, W, B), ans);
  }
  if (Y + 1 < W && !check.at(X).at(Y + 1) && chizu.at(X).at(Y + 1) == '.') {
    ans = max(tansaku(chizu, check, X, Y + 1, count + 1, H, W, B), ans);
  }
  return ans;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> chizu(H, vector<char>(W));
  vector<vector<bool>> check(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> chizu.at(i).at(j);
    }
  }
  int answer = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<int>> B(H, vector<int>(W, 1000));
      answer = max(tansaku(chizu, check, i, j, 0, H, W, B), answer);
    }
  }
  cout << answer << endl;
}
