#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int out(const T &t) {
  print(t);
  putchar('\n');
  return 0;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return (gcd(b, a % b));
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const long long INF = 1e18;
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;
}
long long H, W;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool isRange(long long y, long long x) {
  return (0 <= y && y < H && 0 <= x && x < W);
}
int main() {
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  long long maxnum = 0;
  for (long long i = 0; i < H; i++) {
    for (long long j = 0; j < W; j++) {
      queue<pair<long long, long long>> q;
      pair<long long, long long> p;
      vector<vector<long long>> num(20, vector<long long>(20, -1));
      long long maxtmp = 0;
      if (S[i][j] == '.') {
        q.push(pair<long long, long long>(i, j));
        while (q.size()) {
          p = q.front();
          q.pop();
          for (long long i = 0; i < 4; i++) {
            long long ny = p.first + dy[i], nx = p.second + dx[i];
            if (isRange(ny, nx) && S[ny][nx] == '.' && num[ny][nx] == -1) {
              num[ny][nx] = num[p.first][p.second] + 1;
              chmax(maxnum, num[ny][nx]);
              q.push(pair<long long, long long>(ny, nx));
            }
          }
        }
        chmax(maxnum, maxtmp);
      }
    }
  }
  if (maxnum == 0) {
    cout << 0 << "\n";
  } else {
    cout << maxnum + 1 << "\n";
  }
  return 0;
}
