#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bool isinside(int a, int b, int c, int d) {
  if (a >= 0 && a < c && b >= 0 && b < d) {
    return true;
  } else {
    return false;
  }
}
int bfs(int &i, int &j, int &k, int &l, vector<vector<char>> &grid,
        vector<vector<bool>> &seen) {
  int dist = 0;
  vector<queue<pair<int, int>>> vq;
  queue<pair<int, int>> q;
  q.push({i, j});
  vq.push_back(q);
  queue<pair<int, int>> temp;
  temp.push({i, j});
  while (true) {
    queue<pair<int, int>> qp = vq.back();
    if (temp.empty()) {
      break;
    }
    while (!temp.empty()) {
      temp.pop();
    }
    while (!qp.empty()) {
      pair<int, int> p = qp.front();
      qp.pop();
      int x = p.first;
      int y = p.second;
      if (seen[x][y]) {
        continue;
      }
      seen[x][y] = true;
      if (x == k && y == l) {
        dist = vq.size() - 1;
        break;
      }
      for (pair<int, int> pp : dir) {
        int m = pp.first + x;
        int n = pp.second + y;
        if (isinside(m, n, grid.size(), grid[0].size()) && grid[m][n] == '.') {
          temp.push({m, n});
        }
      }
    }
    vq.push_back(temp);
  }
  return dist;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> grid(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '.') {
        for (int k = 0; k < h; k++) {
          for (int l = 0; l < w; l++) {
            if (grid[k][l] == '.') {
              vector<vector<bool>> seen(h, vector<bool>(w));
              ans = max(ans, bfs(i, j, k, l, grid, seen));
            }
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
