#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;
int W, H;
vector<vector<char>> s;
vector<vector<int>> cost;
int bfs(int a, int b, int c, int d) {
  int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
  queue<pair<int, int>> que;
  que.push(make_pair(a - 1, b - 1));
  cost[a - 1][b - 1] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p == make_pair(c - 1, d - 1)) {
      return cost[p.first][p.second];
    }
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if (s[ny][nx] == '#') continue;
      if (cost[ny][nx] != -1) continue;
      cost[ny][nx] = cost[p.first][p.second] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  return -1;
}
int main() {
  cin >> H >> W;
  s = vector<vector<char>>(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  int max_cost = 0;
  for (int a = 1; a <= H; a++) {
    for (int b = 1; b <= W; b++) {
      for (int c = 1; c <= H; c++) {
        for (int d = 1; d <= W; d++) {
          cost = vector<vector<int>>(H, vector<int>(W, -1));
          int dcost = bfs(a, b, c, d);
          max_cost = max(max_cost, dcost);
        }
      }
    }
  }
  cout << max_cost << endl;
}
