#include <bits/stdc++.h>
using namespace std;
const int MAX_SEG = 9765625 * 5;
const long long M = (long long)1e13;
const int MAX_CIR = 39062500 * 5;
long long A[4], B[4], C[4], D[4], p;
long long mul(long long a, long long b, long long p) {
  a %= p;
  b %= p;
  long long ret = 0;
  while (b) {
    if (b & 1)
      if ((ret += a) >= p) ret -= p;
    if ((a <<= 1) >= p) a -= p;
    b >>= 1;
  }
  return ret;
}
void mul(long long A[], long long B[], long long C[], long long p) {
  C[0] = (mul(A[0], B[0], p) + mul(A[1], B[2], p)) % p;
  C[1] = (mul(A[0], B[1], p) + mul(A[1], B[3], p)) % p;
  C[2] = (mul(A[2], B[0], p) + mul(A[3], B[2], p)) % p;
  C[3] = (mul(A[2], B[1], p) + mul(A[3], B[3], p)) % p;
  A[0] = C[0];
  A[1] = C[1];
  A[2] = C[2];
  A[3] = C[3];
}
long long fibonacci(long long n, long long p) {
  if (!n) return 0;
  --n;
  A[0] = A[1] = A[2] = 1;
  A[3] = 0;
  D[0] = D[3] = 1;
  D[1] = D[2] = 0;
  while (n) {
    if (n & 0x1) mul(D, A, C, p);
    mul(A, A, C, p);
    n >>= 1;
  }
  return D[0];
}
vector<int> pos;
void pre() {
  int a, b, c, rem = p % MAX_SEG;
  pos.clear();
  a = 0;
  if (a == rem) pos.push_back(0);
  b = 1;
  if (b == rem) pos.push_back(1);
  int i;
  for (i = 2; i <= MAX_CIR; ++i) {
    c = a + b;
    if (c >= MAX_SEG) c -= MAX_SEG;
    if (c == rem) pos.push_back(i);
    a = b;
    b = c;
    if (pos.size() == 4) break;
  }
}
int main() {
  while (1 == scanf("%I64d", &p)) {
    if (p <= 1) {
      cout << (int)p << endl;
      continue;
    }
    pre();
    long long ans = (long long)1e17;
    int i;
    for (i = 0; i < pos.size(); ++i) {
      long long now = pos[i];
      if (now <= 1) now += MAX_CIR;
      long long E[4], F[4], G[4];
      fibonacci(MAX_CIR + 1, M);
      memcpy(E, D, sizeof D);
      fibonacci(now, M);
      memcpy(F, D, sizeof D);
      while (now < (long long)(1e13 + 5e12) && now <= ans) {
        if (F[0] == p) {
          if (now < ans) ans = now;
        }
        now += MAX_CIR;
        mul(F, E, G, M);
      }
    }
    if (ans > 1e16) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
