#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
int n,m,i,k=0,j;
struct node *head,*tail,*p,*q;
while(~scanf("%d",&m)&&m!=0)
{
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
head->data=1;
tail=head;
for(i=2;i<=m;i++)
{
p=(struct node*)malloc(sizeof(struct node));
p->data=i;
tail->next=p;
tail=p;
}
tail->next=head;
p=head;
k=0;
j=0;
q=tail->next;
while(p->next!=NULL)
{
j++;
if(j==4)
{
q=p->next;
if(q->data==1)
break;
else {
p->next=p->next->next;
free(q);
j=0;
k++;
}
}
p=p->next;
}
printf("%d\n",k+1);
}
}