#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;
const double pi = acos(-1);
const ll MOD = 1e9 + 7;
const ll INF = (1LL << 60);
int main() {
  int h, w;
  cin >> h >> w;
  char graph[h][w];
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) cin >> graph[i][j];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      if (graph[i][j] == '#')
        continue;
      else {
        vvi d(h, vi(w, 1000));
        d[i][j] = 0;
        queue<pair<int, int>> q;
        q.push({i, j});
        while (q.size() != 0) {
          auto p1 = q.front();
          q.pop();
          vector<pair<int, int>> move;
          move.push_back(make_pair(1, 0));
          move.push_back(make_pair(-1, 0));
          move.push_back(make_pair(0, 1));
          move.push_back(make_pair(0, -1));
          for (auto p : move) {
            int dx = p.first, dy = p.second;
            int x = dx + p1.first, y = dy + p1.second;
            if (x < 0 || y < 0 || x >= h || y >= w)
              continue;
            else if (graph[x][y] == '#')
              continue;
            else if (d[x][y] < d[p1.first][p1.second] + 1)
              continue;
            else {
              d[x][y] = d[p1.first][p1.second] + 1;
              q.push({x, y});
            }
          }
        }
        for (int k = 0; k < (int)(h); k++) {
          for (int l = 0; l < (int)(w); l++) {
            if (d[k][l] != 1000) {
              ans = max(ans, d[k][l]);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
