#include<iostream>
using namespace std;
struct chainNode
{
int element;
chainNode* next;
chainNode(int element, chainNode *n)
{
this->element =element;
this->next = n;
}
};
class mylinkqueue
{
public:
mylinkqueue();
~mylinkqueue();
int getsize();
void pop();
int front();
void push(int);
private:
int size;
chainNode* thefront;
chainNode* theback;
};
mylinkqueue::mylinkqueue()
{
size = 0;
thefront = NULL;
theback = NULL;
}
mylinkqueue::~mylinkqueue()
{
chainNode *c=thefront;
while(c!=NULL)
{c=c->next;
delete thefront;
thefront = c;}
}
int mylinkqueue::getsize()
{
return size;
}
void mylinkqueue::pop()
{
if(thefront==NULL)
{
return;
}
chainNode* nextNode = thefront->next;
delete thefront;
thefront = nextNode;
size--;
}
void mylinkqueue::push(int a)
{
chainNode* newNode = new chainNode(a,NULL);
if(size==0)
thefront = newNode;
else
{
theback->next=newNode;
}
theback= newNode;
size++;
}
int mylinkqueue::front()
{
return thefront->element;
}
int main()
{
int n;
cin>>n;
mylinkqueue q;
for(int i=1;i<n+1;i++)
{
q.push(i);
}
int a=0;
while(q.getsize ()>1)
{
q.pop();
a=q.front() ;
q.pop() ;
q.push(a);
}
cout<<q.front() ;
}