#include <bits/stdc++.h>
using namespace std;
int h, w;
bool legalMove(int y, int x) {
  if (y < 0 || y >= h || x < 0 || x >= w)
    return false;
  else
    return true;
}
int calcMaxLong(int maxLength, int length, vector<string> &s,
                vector<pair<int, int>> &queue, vector<vector<bool>> &after) {
  int size = queue.size();
  for (int i = 0; i < (size); i++) {
    int y = queue[0].first;
    int x = queue[0].second;
    queue.erase(queue.begin());
    after[y][x] = true;
    if (legalMove(y - 1, x) && s[y - 1][x] == '.' && after[y - 1][x] == false) {
      pair<int, int> p(y - 1, x);
      queue.push_back(p);
    }
    if (legalMove(y, x + 1) && s[y][x + 1] == '.' && after[y][x + 1] == false) {
      pair<int, int> p(y, x + 1);
      queue.push_back(p);
    }
    if (legalMove(y + 1, x) && s[y + 1][x] == '.' && after[y + 1][x] == false) {
      pair<int, int> p(y + 1, x);
      queue.push_back(p);
    }
    if (legalMove(y, x - 1) && s[y][x - 1] == '.' && after[y][x - 1] == false) {
      pair<int, int> p(y, x - 1);
      queue.push_back(p);
    }
    if (length > maxLength) maxLength = length;
  }
  if (queue.size() == 0) return maxLength;
  length++;
  calcMaxLong(maxLength, length, s, queue, after);
}
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); i++) {
    cin >> s[i];
  }
  int max = 0;
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      if (s[i][j] == '#') continue;
      pair<int, int> now(i, j);
      vector<pair<int, int>> queue;
      queue.push_back(now);
      vector<vector<bool>> after(h);
      for (int k = 0; k < (h); k++) {
        vector<bool> a(w);
        after[k] = a;
      }
      int length = calcMaxLong(0, 0, s, queue, after);
      if (max < length) max = length;
    }
  }
  cout << max << endl;
}
