#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 main() {
  int h, w;
  cin >> h >> w;
  char grid[25][25];
  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] == '.') {
        vector<vector<bool>> seen(h, vector<bool>(w));
        vector<vector<int>> dist(h, vector<int>(w));
        dist[i][j] = 0;
        queue<pair<int, int>> temp;
        temp.push({i, j});
        while (!temp.empty()) {
          pair<int, int> p = temp.front();
          temp.pop();
          int x = p.first;
          int y = p.second;
          seen[x][y] = true;
          for (pair<int, int> pp : dir) {
            int m = pp.first + x;
            int n = pp.second + y;
            if (isinside(m, n, h, w) && grid[m][n] == '.' && !seen[m][n]) {
              dist[m][n] = 1 + dist[x][y];
              ans = max(ans, dist[m][n]);
              temp.push({m, n});
            }
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
