#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;
  cin >> H >> W;
  vector<string> second(H);
  for (long long i = 0; i < (long long)(H); i++) {
    cin >> second[i];
  }
  long long max_dis = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < second[i].size(); j++) {
      if (second[i].at(j) == '.') {
        int i_x = i;
        int i_y = j;
        queue<pair<int, int>> que;
        que.push(make_pair(i_x, i_y));
        vector<vector<long long>> dist(H, vector<long long>(W));
        dist[i_x][i_y] = 0;
        while (!que.empty()) {
          pair<int, int> fir;
          fir = que.front();
          que.pop();
          int if_x = fir.first;
          int if_y = fir.second;
          for (int k = 0; k < 4; k++) {
            int i2_x = if_x + dx[k];
            int i2_y = if_y + dy[k];
            if (i2_x >= 0 && i2_x < H && i2_y >= 0 && i2_y < W &&
                second[i2_x][i2_y] != '#') {
              if (dist[i2_x][i2_y] != 0) continue;
              que.push(make_pair(i2_x, i2_y));
              dist[i2_x][i2_y] = dist[if_x][if_y] + 1;
              max_dis = max(max_dis, dist[i2_x][i2_y]);
            }
          }
        }
      }
    }
  }
  cout << max_dis << endl;
}
