#include <bits/stdc++.h>
using namespace std;
long long int H, W, Ans = 0;
vector<string> table;
vector<vector<long long int>> V;
vector<long long int> dx{-1, 0, 0, 1};
vector<long long int> dy{0, -1, 1, 0};
queue<pair<long long int, long long int>> Q;
void bfs() {
  if (!Q.empty()) {
    long long int Y = Q.front().first, X = Q.front().second;
    Q.pop();
    for (long long int i = 0; i < 4; i++) {
      long long int y = Y + dy[i], x = X + dx[i];
      if (y < 0 || y >= H || x < 0 || x >= W) continue;
      if (table[y][x] == '#' || V[y][x] != -1) continue;
      V[y][x] = V[Y][X] + 1;
      Ans = max(Ans, V[y][x]);
      Q.push({y, x});
    }
    bfs();
  }
}
int main() {
  cin >> H >> W;
  for (long long int i = 0; i < H; i++) {
    string S;
    cin >> S;
    table.push_back(S);
  }
  V.resize(H);
  for (long long int i = 0; i < H; i++) {
    for (long long int j = 0; j < W; j++) {
      V[i].push_back(-1);
    }
  }
  for (long long int i = 0; i < H; i++) {
    for (long long int j = 0; j < W; j++) {
      for (long long int k = 0; k < H; k++) {
        for (long long int l = 0; l < W; l++) {
          V[k][l] = -1;
        }
      }
      V[i][j]++;
      Q.push({i, j});
      bfs();
    }
  }
  cout << Ans;
}
