#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
void cum_sum(int N, vector<double> a, vector<double>& s) {
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + a[i];
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;
}
bool is_prime(long long n) {
  if (n <= 1) return false;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p == 0) return false;
  }
  return true;
}
int getdigit(long long num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int H, W;
  int maxi = 0;
  cin >> H >> W;
  vector<vector<char>> second(H, vector<char>(W));
  for (long long i = 0; i < (long long)(H); i++) {
    for (long long j = 0; j < (long long)(W); j++) {
      cin >> second[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int sx, sy;
      if (second[i][j] == '.') {
        sx = i;
        sy = j;
      }
      vector<vector<int>> dist(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      dist[sx][sy] = 0;
      que.push(make_pair(sx, sy));
      while (!que.empty()) {
        auto v = que.front();
        que.pop();
        int vx = v.first;
        int vy = v.second;
        for (int k = 0; k < 4; k++) {
          int nx = vx + dx[k];
          int ny = vy + dy[k];
          if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
          if (second[nx][ny] == '#') continue;
          if (dist[nx][ny] != -1) continue;
          dist[nx][ny] = dist[vx][vy] + 1;
          que.push(make_pair(nx, ny));
        }
      }
      for (long long l = 0; l < (long long)(H); l++) {
        for (long long m = 0; m < (long long)(W); m++) {
          maxi = max(maxi, dist[l][m]);
        }
      }
    }
  }
  cout << maxi << endl;
}
