#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long INFL = 9 * 1e18;
long long inline digit(long long num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
}
template <typename T>
inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
}
template <typename T>
inline T power(T a, T b) {
  T tmp = 1;
  for (int i = 0; i < ((int)(b)); ++i) {
    tmp *= a;
  }
  return tmp;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) { return c - '0'; }
template <typename T>
bool isOk(T key, T value) {
  return key >= value;
}
template <typename T>
T binary_search(vector<T> a, T key) {
  T ok = a.size() - 1;
  T ng = 0;
  while (abs(ok - ng) > 1) {
    T mid = (ok + ng) / 2;
    if (isOk(key, a[mid]))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}
bool isPrime(long long n) {
  for (int i = 2; n >= i * i; ++i) {
    if (!(n % i)) return false;
  }
  return true;
}
vector<long long> primes(long long n) {
  vector<long long> v;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      v.push_back(i);
    }
  }
  if (n != 1) v.push_back(n);
  return v;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < ((int)(h)); ++i) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < ((int)(h)); ++i) {
    for (int j = 0; j < ((int)(w)); ++j) {
      if (s[i][j] == '#') continue;
      vector<vector<int> > dist(h, vector<int>(w));
      queue<pair<int, int> > que;
      dist[i][j] = 0;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<int, int> cur = que.front();
        que.pop();
        for (int i = 0; i < ((int)(4)); ++i) {
          pair<int, int> next = cur;
          next.first += dy[i];
          next.second += dx[i];
          if (next.first < 0 || next.first >= h || next.second < 0 ||
              next.second >= w)
            continue;
          if (s[next.first][next.second] == '#') continue;
          if (dist[next.first][next.second] == 0) {
            que.push(next);
            dist[next.first][next.second] = dist[cur.first][cur.second] + 1;
            ans = max(ans, dist[next.first][next.second]);
          }
        }
      }
    }
  }
  cout << (ans) << endl;
  return 0;
}
