import sys
from collections import deque
n = int(sys.stdin.readline())
d = deque()
for i in range(n):
    d.append(i + 1)
while len(d) > 1:
    d.popleft()
    d.append(d.popleft())
print(d.pop())

c2730f3a1460be9ab9758eb34a0bb0427daf0d8f
<mask token>

<mask token>
for i in range(n):
    d.append(i + 1)
while len(d) > 1:
    d.popleft()
    d.append(d.popleft())
print(d.pop())

<mask token>
n = int(sys.stdin.readline())
d = deque()
for i in range(n):
    d.append(i + 1)
while len(d) > 1:
    d.popleft()
    d.append(d.popleft())
print(d.pop())

import sys
from collections import deque
n = int(sys.stdin.readline())
d = deque()
for i in range(n):
    d.append(i + 1)
while len(d) > 1:
    d.popleft()
    d.append(d.popleft())
print(d.pop())
