#include <bits/stdc++.h>
using namespace std;
int w, h;
vector<string> m;
int memo[50][50];
int mx;
int f(int sy, int sx) {
  int dy[4] = {-1, 0, 0, 1};
  int dx[4] = {0, -1, 1, 0};
  memset(memo, 0, sizeof(memo));
  memo[sy][sx] = 1;
  queue<int> q1, q2, q3;
  q1.push(sy);
  q2.push(sx);
  q3.push(0);
  while (!q1.empty()) {
    int y = q1.front();
    int x = q2.front();
    int c = q3.front();
    q1.pop();
    q2.pop();
    q3.pop();
    mx = max(mx, c);
    for (int t = 0; t < 4; t++) {
      int y1 = y + dy[t];
      int x1 = x + dx[t];
      if (y1 < 0 || y1 >= h) continue;
      if (x1 < 0 || x1 >= w) continue;
      if (m[y1][x1] == '#') continue;
      if (memo[y1][x1] == 1) continue;
      memo[y1][x1] = 1;
      q1.push(y1);
      q2.push(x1);
      q3.push(c + 1);
    }
  }
  return -1;
}
int main() {
  mx = 0;
  cin >> h >> w;
  for (long long i = (0); i < (h); ++i) {
    string s;
    cin >> s;
    m.push_back(s);
  }
  for (long long y = (0); y < (h); ++y) {
    for (long long x = (0); x < (w); ++x) {
      memset((memo), (0), sizeof(memo));
      f(y, x);
    }
  }
  cout << mx << endl;
  return 0;
}
