#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
void ABC151D() {
  int H, W;
  cin >> H >> W;
  vvi grid(H, vi(W));
  for (int i = 0; i < H; ++i) {
    string S;
    cin >> S;
    for (int j = 0; j < W; ++j) {
      grid[i][j] = S[j] == '.' ? 1 : 0;
    }
  }
  int maxDist = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      vvi path(grid);
      vvi dist(H, vi(W));
      queue<pair<int, int> > qu;
      qu.push({i, j});
      path[i][j] = -1;
      int dd = 0;
      while (!qu.empty()) {
        auto p = qu.front();
        qu.pop();
        int x = p.first;
        int y = p.second;
        int d = dist[x][y];
        vector<pair<int, int> > dx = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
        for (int i = 0; i < 4; ++i) {
          int xx = x + dx[i].first;
          int yy = y + dx[i].second;
          if (xx < 0 || yy < 0 || xx >= H || yy >= W) continue;
          if (path[xx][yy] <= 0) continue;
          path[xx][yy] = -1;
          dist[xx][yy] = d + 1;
          dd = d + 1;
          qu.push({xx, yy});
        }
      }
      maxDist = max(maxDist, dd);
    }
  }
  cout << maxDist << endl;
}
int main() {
  ABC151D();
  return 0;
}
