#include <bits/stdc++.h>
using namespace std;
int H, W;
int Two2One(int x, int y) { return y * W + x; }
pair<int, int> One2Two(int pos) {
  int x = pos % W;
  int y = pos / W;
  return make_pair(x, y);
}
int DFS(vector<vector<bool>> &s, vector<vector<bool>> &passed, int xs, int ys,
        int distance) {
  if (xs < 0 || ys < 0 || xs >= W || ys >= H) return distance - 1;
  if (!s[ys][xs]) return distance - 1;
  if (passed[ys][xs]) return distance - 1;
  passed[ys][xs] = true;
  int maxD = 0;
  maxD = max(maxD, DFS(s, passed, xs + 1, ys, distance + 1));
  maxD = max(maxD, DFS(s, passed, xs - 1, ys, distance + 1));
  maxD = max(maxD, DFS(s, passed, xs, ys + 1, distance + 1));
  maxD = max(maxD, DFS(s, passed, xs, ys - 1, distance + 1));
  return maxD;
}
int main() {
  cin >> H >> W;
  vector<vector<bool>> S(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    string temp;
    cin >> temp;
    for (int j = 0; j < W; j++) S[i][j] = (temp[j] == '.');
  }
  int maxDistance = 0;
  for (int s = 0; s < H * W; s++) {
    auto pos_s = One2Two(s);
    if (!S[pos_s.second][pos_s.first]) continue;
    vector<vector<bool>> passed(H, vector<bool>(W, false));
    int distance = DFS(S, passed, pos_s.first, pos_s.second, 0);
    maxDistance = max(maxDistance, distance);
  }
  cout << maxDistance;
  return 0;
}
