/*   @JUDGE_ID:   1705PZ   151   C */
#include <stdio.h>
#include <stdlib.h>

int main(){
int n,i,now,count,count1,next;
int *table;
while(1){
	scanf("%d",&n);
	if(n == 0)
		break;
	table = (int *)malloc(sizeof(int) * n);
	next = 0;
	while(1){
		for(i = 0;i < n;i++)
			*(table + i) = 1;
		*table = 0;
		next++;
		now = 0;
		count = 0;
		while(1){
			count++;
			if(count == n - 1)
				break;
			count1 = 0;
			while(1){
				now++;
				now %= n;
				if(*(table + now) == 1)
					count1++;
				if(count1 == next)
					break;
				}
			*(table + now) = 0;
			}
		if(*(table + 12) == 1)
			break;
		}
	printf("%d\n",next);
	free(table);
	}
return 0;
}
@END_OF_SOURCE_CODE
