N = int(input().strip()) a = '0' txt = '285714' while True: if len(a) > N: break a += txt print(a[N])