#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
template <typename T>
void printArray(T a) {
  for (auto i : a) cout << i << " ";
  cout << "\n";
}
template <typename T>
void print2DArray(T a) {
  for (auto i : a) {
    for (auto j : i) cout << j << " ";
    cout << "\n";
  }
  cout << "\n";
}
int main(int argc, char *argv[]) {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int h = 1;
  int w = 1;
  cin >> h >> w;
  vector<vector<char>> s = vector<vector<char>>(h, vector<char>(w));
  for (size_t i = 0; i < h; i++) {
    for (size_t j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int numV = h * w;
  vector<vector<int>> dist =
      vector<vector<int>>(numV, vector<int>(numV, 100000));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int u = i * w + j;
      if (s[i][j] == '#') {
        continue;
      }
      if (i == j) {
        dist[u][u] = 0;
      }
      if (j + 1 < w && s[i][j + 1] != '#') {
        int v = i * w + (j + 1);
        dist[u][v] = 1;
        dist[v][u] = 1;
      }
      if (i + 1 < h && s[i + 1][j] != '#') {
        int v = (i + 1) * w + j;
        dist[u][v] = 1;
        dist[v][u] = 1;
      }
      if (j - 1 >= 0 && s[i][j - 1] != '#') {
        int v = i * w + (j - 1);
        dist[u][v] = 1;
        dist[v][u] = 1;
      }
      if (i - 1 >= 0 && s[i - 1][j] != '#') {
        int v = (i - 1) * w + j;
        dist[u][v] = 1;
        dist[v][u] = 1;
      }
    }
  }
  for (size_t k = 0; k < numV; k++) {
    for (size_t i = 0; i < numV; i++) {
      for (size_t j = 0; j < numV; j++) {
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
  ulli max = 0;
  for (size_t i = 0; i < numV; i++) {
    for (size_t j = 0; j < numV; j++) {
      if (dist[i][j] != 100000 && dist[i][j] > max) {
        max = dist[i][j];
      }
    }
  }
  cout << max << "\n";
  return 0;
}
