program sdf;
var
i,n:integer;
a,b:array[1..1000]of longint;
begin
assign(input,'chashu.in');
assign(output,'chashu.out');
reset(input);
rewrite(output);
readln(n);
a[1]:=8;
b[1]:=1;
for i:=2 to n do
begin
a[i]:=a[i-1]*9+b[i-1];
b[i]:=b[i-1]*9+a[i-1];
if a[i]>100000 then a[i]:=a[i] mod 12345;
if b[i]>100000 then b[i]:=b[i] mod 12345;
end;
writeln (a[n] mod 12345);
close(input);
close(output);
end.