processors =500
def a[1001]
def kone[500]
i=nprocessors


thingplus%=pid*2
thing%=thingplus%-1

a[thing%]=thing%
a[thingplus%]=thingplus%


j=0
k=0
while (i>=pid)
{	
	result%=a[thing%]
		
	if (a[thing%] < a[thingplus%])
	{
		result%=a[thingplus%]
	
	}
	a[pid]=result%

	if (k==1)
	{
		if (pid==i)
		{
			a[pid]=a[thing%]
		}
	}		

	b=i
	i = i/2
	c=b.2		
	if (c!=0)
	{
		if (i!=0)
		{	
			i++
			k=1
		}
	} else {

		k=0
	}	

}

if (pid==1)
{
	println a[1]
}