# FibPeriodMODm-q17
# Section 6, Q.17 c), p.25, p.250
# input: 5 or 7

m = int(input("m=? "))
a = 0; b = 1
l = 0
while True:
  l += 1
  c = a
  a = b
  b = (b+c)%m
  if (a == 0) and (b == 1):
    break
print(l)
