#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int, int>;
using Mll = map<ll, ll>;
using UMi = unordered_map<int, int>;
using UMll = unordered_map<ll, ll>;
using Pi = pair<int, int>;
using Pll = pair<ll, ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int, vector<int>, greater<int>>;
using pqsi = priority_queue<int, vector<int>, less<int>>;
using pqgll = priority_queue<int, vector<int>, greater<int>>;
using pssll = priority_queue<int, vector<int>, less<int>>;
template <class T>
using vec = vector<T>;
vector<vector<char>> S;
long long H, W;
long long solve(long long x, long long y) {
  vector<vector<long long>> maze;
  maze.resize(H, vector<long long>(W, -1));
  maze[x][y] = 0;
  queue<pair<long long, long long>> q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    long long x = p.first;
    long long y = p.second;
    if (x + 1 < H) {
      if (S[x + 1][y] == '.') {
        if (maze[x + 1][y] == -1) {
          maze[x + 1][y] = maze[x][y] + 1;
          q.push(make_pair(x + 1, y));
        }
      }
    }
    if (y + 1 < W) {
      if (S[x][y + 1] == '.') {
        if (maze[x][y + 1] == -1) {
          maze[x][y + 1] = maze[x][y] + 1;
          q.push(make_pair(x, y + 1));
        }
      }
    }
    if (x - 1 >= 0) {
      if (S[x - 1][y] == '.') {
        if (maze[x - 1][y] == -1) {
          maze[x - 1][y] = maze[x][y] + 1;
          q.push(make_pair(x - 1, y));
        }
      }
    }
    if (y - 1 >= 0) {
      if (S[x][y - 1] == '.') {
        if (maze[x][y - 1] == -1) {
          maze[x][y - 1] = maze[x][y] + 1;
          q.push(make_pair(x, y - 1));
        }
      }
    }
  }
  long long largest = -1;
  for (long long h = 0; h < H; h++) {
    for (long long w = 0; w < W; w++) {
      largest = max(largest, maze[h][w]);
    }
  }
  return largest;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> H >> W;
  S.resize(H, vector<char>(W, ' '));
  for (long long h = 0; h < H; h++) {
    for (long long w = 0; w < W; w++) {
      cin >> S[h][w];
    }
  }
  long long ans = -1;
  for (long long h = 0; h < H; h++) {
    for (long long w = 0; w < W; w++) {
      if (h == 0 || h == H - 1 || w == 0 || w == W - 1) {
        if (S[h][w] == '.') {
          ans = max(ans, solve(h, w));
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
