#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans[25]={1};
int now, n, la=0;
void m() {
now=0;
for(int i=0; i<n; i++){
ans[now]*=4;
for(int j=now+1;j<25;j++) {
ans[j]*=4;
ans[j]+=ans[j-1]/1000;
ans[j-1]=ans[j-1]%1000;
}
if(ans[now]%1000==0)
n++;
}
}
void d() {
for(int now=24; now>0; now--){
ans[now-1]+=ans[now]%3*1000;
ans[now]/=3;
}
ans[0]/=3;
}
void s() {
ans[0]--;
for(int now=0; ans[now]<0; now++){
ans[now+1]--;
ans[now]=1000+ans[now];
}
}
signed main(){
cin>>n;
m();
s();
d();
int i;
for(i=24;i>=0;i--){
if(ans[i]!=0)
break;
}
cout<<ans[i];
i--;
for(;i>=0;i--){
cout << setw(3) << setfill('0') <<ans[i];
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwppbnQgYW5zWzI1XT17MX07CmludCBub3csIG4sIGxhPTA7Cgp2b2lkIG0oKSB7Cglub3c9MDsKCWZvcihpbnQgaT0wOyBpPG47IGkrKyl7CgkJYW5zW25vd10qPTQ7CgkJZm9yKGludCBqPW5vdysxO2o8MjU7aisrKSB7CgkJCWFuc1tqXSo9NDsKCQkJYW5zW2pdKz1hbnNbai0xXS8xMDAwOwogICAgICAJYW5zW2otMV09YW5zW2otMV0lMTAwMDsKCQkKCQl9CgkJaWYoYW5zW25vd10lMTAwMD09MCkKICAgICAgCW4rKzsKICAgIH0KfQp2b2lkIGQoKSB7Cglmb3IoaW50IG5vdz0yNDsgbm93PjA7IG5vdy0tKXsKCQlhbnNbbm93LTFdKz1hbnNbbm93XSUzKjEwMDA7CgkJYW5zW25vd10vPTM7CiAgICB9CiAgIGFuc1swXS89MzsKfQp2b2lkIHMoKSB7CglhbnNbMF0tLTsKCWZvcihpbnQgbm93PTA7IGFuc1tub3ddPDA7IG5vdysrKXsKCQlhbnNbbm93KzFdLS07CgkJYW5zW25vd109MTAwMCthbnNbbm93XTsKICAgIH0KfQpzaWduZWQgbWFpbigpewogICBjaW4+Pm47CiAgIG0oKTsKICAgcygpOwogICBkKCk7CiAgIAogICBpbnQgaTsKICAgZm9yKGk9MjQ7aT49MDtpLS0pewogICAJaWYoYW5zW2ldIT0wKQogICAJCWJyZWFrOwogICB9CiAgIGNvdXQ8PGFuc1tpXTsKICAgaS0tOwogICBmb3IoO2k+PTA7aS0tKXsKICAgCWNvdXQgPDwgc2V0dygzKSA8PCBzZXRmaWxsKCcwJykgPDxhbnNbaV07CiAgIH0KICAgcmV0dXJuIDA7Cn0=