def ip():return int(input()) def mp():return map(int, input().split()) def lmp():return list(map(int, input().split())) # 岩プロコン2 F No.3264 岩井数 N = ip() i = 1000 M = 10**9 K = [1] for j in range(1100): K.append(K[-1] * 10 % N) # print(K[:10]) while True: ip = i % N si = str(i) si_ = si[::-1] i_ = int(si_) ip_ = i_ % N ti = int(si + si_ + '9') L = len(si) if L >= 5 and (ip * K[L+1] % N + ip_ * 10 % N + 9) % N == 0: print(ti) exit() for j in range(10): ti = int(si + str(j) + si_ + '9') if (ip * K[L+2] % N + j * K[L+1] % N + ip_ * 10 % N + 9) % N == 0: print(ti) exit() i += 1