#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
void prints() {}
template <typename T>
void get(T* x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T>
void get(T& x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T, typename... A>
void print(T x, A... r) {
  cout << x << " ";
  print(r...);
}
template <typename T, typename... A>
void prints(T x, A... r) {
  cout << x << " ";
  prints(r...);
}
const long long int mod = 1e9 + 7;
const long long int N = 21;
char grid[N][N];
long long int h, w;
bool bounds(long long int i, long long int j) {
  return 0 <= i && i <= h && j <= w && 0 <= j;
}
long long int dist(long long int i, long long int j, long long int a,
                   long long int b) {
  if (grid[i][j] == '#' || grid[a][b] == '#') {
    return -1;
  }
  queue<pair<long long ll, long long ll> > q;
  bool vis[h][w];
  memset(vis, 0, sizeof(vis));
  q.push({i, j});
  vis[i][j] = true;
  long long int d[h][w];
  memset(d, 0, sizeof(d));
  while (!q.empty()) {
    long long int i = q.front().first;
    long long int j = q.front().second;
    q.pop();
    vector<pair<long long ll, long long ll> > v = {
        {i, j + 1}, {i, j - 1}, {i + 1, j}, {i - 1, j}};
    for (auto p : v) {
      long long int x = p.first;
      long long int y = p.second;
      if (bounds(x, y) && grid[x][y] == '.') {
        q.push({x, y});
        d[x][y] = d[i][j] + 1;
        if (x == a && y == b) {
          return d[x][y];
        }
      }
    }
  }
  return -1;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (long long int i = 0; i < h; ++i) {
    for (long long int j = 0; j < w; ++j) {
      cin >> grid[i][j];
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; ++i) {
    for (long long int j = 0; j < w; ++j) {
      for (long long int x = 0; x < h; ++x) {
        for (long long int y = 0; y < w; ++y) {
          long long int d = dist(i, j, x, y);
          ;
          ans = max(ans, d);
        }
      }
    }
  }
  print(ans);
  return 0;
}
