#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 1e18;
int main() {
  long long int h, w;
  cin >> h >> w;
  char s[h + 2][w + 2];
  for (long long int i = 0; i < h + 2; i++) {
    for (long long int j = 0; j < w + 2; j++) {
      if (i == 0 || i == h + 1 || j == 0 || j == w + 1)
        s[i][j] = '#';
      else
        cin >> s[i][j];
    }
  }
  long long int m = 0;
  int dx[4] = {0, 1, -1, 0};
  int dy[4] = {1, 0, 0, -1};
  for (long long int i = 1; i < h + 1; i++) {
    for (long long int j = 1; j < w + 1; j++) {
      long long int d[h + 2][w + 2];
      for (int i = 0; i < h + 2; i++) {
        for (int j = 0; j < w + 2; j++) {
          d[i][j] = -1;
        }
      }
      queue<vector<long long int>> que;
      d[i][j] = 0;
      que.push({i, j});
      while (!que.empty()) {
        vector<long long int> v = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
          if (d[v[0] + dx[i]][v[1] + dy[i]] == -1 &&
              s[v[0] + dx[i]][v[1] + dy[i]] == '.') {
            d[v[0] + dx[i]][v[1] + dy[i]] = d[v[0]][v[1]] + 1;
            que.push({v[0] + dx[i], v[1] + dy[i]});
          }
        }
      }
      long long int p = 0;
      for (long long int i = 1; i < h + 1; i++) {
        for (long long int j = 1; j < w + 1; j++) {
          p = max(p, d[i][j]);
        }
      }
      m = max(m, p);
    }
  }
  cout << m << endl;
}
