program circlex;
var
j,i,n:integer;
a:array [0..1000] of longint;
begin
fillchar (a,sizeof(a),0);
assign (input,'circlex.in');
reset (input);
readln (n);
close (input);
assign (output,'circlex.out');
rewrite (output);
a[0]:=1;a[1]:=1;a[2]:=2;a[3]:=4;
for i:=4 to n do begin
a[i]:=a[i-1] mod 12345;
for j:=0 to i-2 do a[i]:=(a[i]+a[j]*a[i-2-j]) mod 12345;
end;
writeln (a[n]);
close (output);
end.