#include <bits/stdc++.h>
using namespace std;
pair<int, int> add(const pair<int, int>& obj1, const pair<int, int>& obj2) {
  int x = obj1.first + obj2.first;
  int y = obj1.second + obj2.second;
  pair<int, int> ret = {x, y};
  return ret;
}
template <typename T>
int BFS(vector<vector<T>>& table, pair<int, int> start) {
  queue<pair<int, int>> q;
  vector<pair<int, int>> move = {{1, 0}, {-1, 0}, {0, 1}, {-1, 0}};
  vector<vector<int>> dp(table.size(),
                         vector<int>(table[0].size(), 2000000000));
  dp[start.first][start.second] = 0;
  q.push(start);
  int max = 0;
  pair<int, int> ret;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    for (int i = 0; i < move.size(); i++) {
      pair<int, int> temp = add(u, move[i]);
      if (0 <= temp.first and temp.first < table.size() and 0 <= temp.second and
          temp.second < table[0].size()) {
        if (table[temp.first][temp.second] == '.' and
            dp[temp.first][temp.second] == 2000000000) {
          dp[temp.first][temp.second] = dp[u.first][u.second] + 1;
          if (dp[temp.first][temp.second] > max) {
            max = dp[temp.first][temp.second];
            ret = {temp.first, temp.second};
          }
          q.push(temp);
        }
      }
    }
  }
  return max;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  int dist = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) cin >> table[i][j];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (table[i][j] == '.') {
        BFS(table, {i, j}) > dist ? dist = BFS(table, {i, j}) : 1;
      }
    }
  }
  cout << dist << endl;
}
