import java.util.Scanner;
public class Main
{
static int k;
static int bnum;
static int m;
static int[] resu=new int[14];
public static void main(String[] args) throws FileNotFoundException
{
Scanner sc=new Scanner(System.in);
sc=new Scanner(new File("/storage/emulated/0/AppProjects/Test/src/joseph"));
while(true){
k=sc.nextInt();
if(k==0)
break;
if(resu[k]!=0){
System.out.println(resu[k]);
continue;
}
boolean is=true;
for(int i=k+k/2+1;i>1;i++){
if(i%(2*k)>=1&&i%(2*k)<=k)
continue;
bnum=k;
m=i;
is=isSafe(2*k,1,k);
if(is){
resu[k]=i;
System.out.println(i);
break;
}
}
}
}
private static boolean isSafe(int n,int s,int t){
if(bnum==0)
return true;
int res=m%n;
if(res==0)
res=n;
if(res>=s&&res<=t)
return false;
bnum--;
return isSafe(n-1,(n-res+s)%n,(n-res+s)%n+k-1);
}
}
sample input:
1
2
3
4
5
6
7
8
9
10
11
12
13
0
sample output:
2
7
5
30
169
441
1872
7632
1740
93313
459901
1358657
2504881