#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = std::numeric_limits<long long>::max();
const int MX = 100101;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first + b.first, a.second + b.second);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
  return pair<T, T>(a.first - b.first, a.second - b.second);
}
template <typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.first + a.second * b.second);
}
template <typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) {
  return (a.first * b.second - a.second * b.first);
}
template <typename T>
void print(vector<T> vec, string name = "") {
  cout << name;
  for (auto u : vec) cout << u << ' ';
  cout << '\n';
}
int N, M;
vector<vector<bool> > grid(30, vector<bool>(30, false));
pair<int, int> tol;
int did = 0;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
bool valid(int first, int second) {
  return first >= 0 and second >= 0 and first < N and second < M;
}
vector<vector<bool> > buvau(30, vector<bool>(30, false));
void dfs1(pair<int, int> c, int dis) {
  if (dis > did) {
    did = dis;
    tol = c;
  }
  buvau[c.first][c.second] = true;
  for (int i = 0; i < 4; ++i) {
    int kx = c.first + dx[i];
    int ky = c.second + dy[i];
    if (valid(kx, ky) and grid[kx][ky] and !buvau[kx][ky])
      dfs1({kx, ky}, dis + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  pair<int, int> start = {-1, -1};
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      char ch;
      cin >> ch;
      grid[i][j] = (ch == '.');
      if (grid[i][j]) start = {i, j};
    }
  }
  dfs1(start, 0);
  buvau = vector<vector<bool> >(30, vector<bool>(30, false));
  did = 0;
  dfs1(tol, 0);
  printf("%d\n", did);
}
