#include using namespace std; using ll = long long; struct stable_int{ long long v; stable_int() : v(0) {} stable_int(long long _v) : v(_v){} stable_int& operator++() { if(__builtin_add_overflow(v, 1, &v))v = std::numeric_limits::max(); return *this; } stable_int& operator--() { if(__builtin_sub_overflow(v, 1, &v))v = std::numeric_limits::min(); return *this; } stable_int operator++(int) { stable_int result = *this; ++*this; return result; } stable_int operator--(int) { stable_int result = *this; --*this; return result; } stable_int& operator+=(const stable_int& rhs) { if(__builtin_add_overflow(v, rhs.v, &v))v = std::numeric_limits::max(); return *this; } stable_int& operator-=(const stable_int& rhs) { if(__builtin_sub_overflow(v, rhs.v, &v))v = std::numeric_limits::min(); return *this; } stable_int& operator*=(const stable_int& rhs) { long long pre = v; if(__builtin_mul_overflow(v, rhs.v, &v)){ v = (pre > 0) ^ (rhs.v > 0) ? std::numeric_limits::min() : std::numeric_limits::max(); } return *this; } stable_int& operator/=(const stable_int& rhs) { v /= rhs.v; return *this ; } stable_int operator+() const { return *this; } stable_int operator-() const { return stable_int() - *this; } friend stable_int operator+(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) += rhs; } friend stable_int operator-(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) -= rhs; } friend stable_int operator*(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) *= rhs; } friend stable_int operator/(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) /= rhs; } friend bool operator==(const stable_int& lhs, const stable_int& rhs) { return (lhs.v == rhs.v); } friend bool operator!=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v != rhs.v); } friend bool operator<(const stable_int& lhs, const stable_int& rhs) { return (lhs.v < rhs.v); } friend bool operator<=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v <= rhs.v); } friend bool operator>(const stable_int& lhs, const stable_int& rhs) { return (lhs.v > rhs.v); } friend bool operator>=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v >= rhs.v); } friend istream& operator>>(istream& is,stable_int& rhs) noexcept { long long _v; rhs = stable_int{(is >> _v, _v)}; return is; } friend ostream& operator << (ostream &os, const stable_int& rhs) noexcept { return os << rhs.v; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; for(int i = 2; i <= 120; i++){ vector a = {1, 1}; while(a.back() < N){ int c = a.size() - i; a.push_back(0); for(int j = a.size() - 1; j >= c && j >= 0; j--){ a.back() += a[j]; } } if(a.back() == N){ cout << i << '\n'; return 0; } } cout << -1 << '\n'; }