//* Problem  : E - Eeny Meeny Moo
//* Contest  : UzhNU Local
//* Origin   : Ulm-1996
//* Type     : Solution
//* Date     : 2008.02.04
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int n;

int prev[200], next[200], val[200];

int survivor(int n, int m)
{
	int i;
	for (i = 0; i < n; i++)
	{
		prev[i] = (i + n - 1) % n;
		next[i] = (i + 1) % n;
		val[i] = i;
	}
	int pos = 0;
	for (int j = 0; j < n - 1; j++)
	{
		int pr = prev[pos], nx = next[pos];
		next[pr] = nx;
		prev[nx] = pr;
		if (pos == 1) return -1;
		for (i = 0; i < m; i++)
			pos = next[pos];
	}
	return 2;
}

int solve()
{
	for (int m = 1; ; m++)
	{
		if (survivor(n, m) == 2) return m;
	}
	return 0;
}

int main()
{
	int nt = 0;
	while (1)
	{
		scanf("%d", &n); if (!n) break;
		printf("%d\n", solve());
	}
	return 0;
}