#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  bool vis[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  int ans = 0;
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < m; y++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          vis[i][j] = (arr[i][j] == '#');
        }
      }
      queue<pair<int, int> > q;
      q.push({x, y});
      vis[x][y] = 1;
      int r = 0;
      while (q.size()) {
        int ps = q.size();
        while (ps--) {
          int vi = q.front().first, vj = q.front().second;
          q.pop();
          for (int i = 0; i < 4; i++) {
            if ((0 <= vi + dx[i] && vi + dx[i] < n) &&
                (0 <= vj + dy[i] && vj + dy[i] < m) &&
                !vis[vi + dx[i]][vj + dy[i]]) {
              vis[vi + dx[i]][vj + dy[i]] = 1;
              q.push({vi + dx[i], vj + dy[i]});
            }
          }
        }
        r++;
      }
      ans = max(ans, r - 1);
    }
  }
  cout << ans << '\n';
}
