#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}
template <class T>
void print(T& x) {
  cout << x << '\n';
}
const int MOD = (int)1e9 + 7;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMint() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a > b) {
    swap(a, b);
  }
  return gcd(a, b % a);
}
long long lcm(long long a, long long b) {
  long long g;
  g = gcd(a, b);
  return a * b / g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long RS(long long N, long long pair<int, int>, long long M) {
  if (pair<int, int> == 0) {
    return 1;
  } else {
    if (pair<int, int> % 2 == 0) {
      long long t = RS(N, pair<int, int> / 2, M);
      return t * t % M;
    } else {
      return N * RS(N, pair<int, int> - 1, M) % M;
    }
  }
}
struct UnionFind {
  vector<int> d;
  UnionFind(int n) : d(n, -1){};
  int deb(int x) { return d[x]; }
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  int unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};
struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int H, W;
int ans;
bool maze[21][21] = {};
void BFS(int x, int y) {
  int checked[21][21] = {};
  checked[x][y] = 1;
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  int max_hosu = 0;
  while (!q.empty()) {
    int first = q.front().first;
    int second = q.front().second;
    q.pop();
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    for (int i = 0; i < (4); ++i) {
      if (first + dx[i] >= 0 && first + dx[i] < H && second + dy[i] >= 0 &&
          second + dy[i] < W) {
        if (maze[first + dx[i]][second + dy[i]]) {
          if (checked[first + dx[i]][second + dy[i]] == 0) {
            q.push(make_pair(first + dx[i], second + dy[i]));
            checked[first + dx[i]][second + dy[i]] = checked[first][second] + 1;
          }
        }
      }
    }
    if (q.empty()) chmax(ans, checked[first][second]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      char ch;
      cin >> ch;
      if (ch == '.') {
        maze[i][j] = true;
      } else {
        maze[i][j] = false;
      }
    }
  }
  ans = 0;
  for (int i = 0; i < (H); ++i) {
    for (int j = 0; j < (W); ++j) {
      BFS(i, j);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
