#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<char> > field(h + 2, vector<char>(w + 2, '#'));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      field[i + 1][j + 1] = c;
    }
  }
  vector<int> res;
  for (int sy = 1; sy <= w; ++sy) {
    for (int sx = 1; sx <= h; ++sx) {
      for (int gy = 1; gy <= w; ++gy) {
        for (int gx = 1; gx <= h; ++gx) {
          vector<vector<int> > dist(h + 1, vector<int>(w + 1, -1));
          dist[sx][sy] = 0;
          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;
              }
            }
          }
          res.push_back(dist[gx][gy]);
        }
      }
    }
  }
  int ans = *max_element(res.begin(), res.end());
  cout << ans;
  return 0;
}
