#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int height, width;
  cin >> height >> width;
  int sy, sx, gy, gx;
  vector<string> field(height);
  for (int h = 0; h < height; ++h) cin >> field[h];
  int counter = 0;
  for (ll q = 0; q < width; q++) {
    for (ll w = 0; w < width; w++) {
      for (ll e = 0; e < height; e++) {
        for (ll r = 0; r < height; r++) {
          sx = q;
          gx = w;
          sy = e;
          gy = r;
          vector<vector<int>> dist(height, vector<int>(width, -1));
          dist[sx][sy] = 0;
          vector<vector<int>> prev_x(height, vector<int>(width, -1));
          vector<vector<int>> prev_y(height, vector<int>(width, -1));
          queue<pair<int, int>> que;
          que.push(make_pair(sx, sy));
          while (!que.empty()) {
            pair<int, int> current_pos = que.front();
            int x = current_pos.first;
            int y = current_pos.second;
            que.pop();
            for (int direction = 0; direction < 4; ++direction) {
              int next_x = x + dx[direction];
              int next_y = y + dy[direction];
              if (field[next_x][next_y] == '#') continue;
              if (dist[next_x][next_y] == -1) {
                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1;
                prev_x[next_x][next_y] = x;
                prev_y[next_x][next_y] = y;
              }
            }
          }
          counter = max(counter, dist[gx][gy]);
        }
      }
    }
  }
  cout << counter << endl;
}
