#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char A[h + 2][w + 2];
  for (int i = 0; i < h + 2; ++i)
    for (int j = 0; j < w + 2; ++j) A[i][j] = '#';
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j) cin >> A[i][j];
  vector<int> G[h * w + 1];
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (A[i][j] != '#') {
        for (int x : {1, -1}) {
          if (A[i][j + x] != '#')
            G[(i - 1) * w + j].push_back((i - 1) * w + j + x);
        }
        for (int y : {1, -1}) {
          if (A[i + y][j] != '#')
            G[(i - 1) * w + j].push_back((i + y - 1) * w + j);
        }
      }
    }
  }
  int max = 0;
  for (int i = 1; i <= h * w; ++i) {
    queue<int> q;
    bool visited[h * w + 1];
    int distance[h * w + 1];
    visited[i] = true;
    distance[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int s = q.front();
      q.pop();
      for (int u : G[s]) {
        if (!visited[u]) {
          visited[u] = true;
          distance[u] = distance[s] + 1;
          q.push(u);
          if (distance[u] > max) max = distance[u];
        }
      }
    }
  }
  cout << max << "\n";
}
