def henkan(n): s = "" while n: if n % 7 >= 10: return -1 s += str(n % 7) n //= 7 return int(s[::-1]) n = int(input()) print(henkan(n))