#include<iostream>
using namespace std;
int main(){
int num,e,a,b,c,d,cishu;
num=0;
e=0;
cin>>cishu;
while(1){
a=e/1000;
b=(e-1000a)/100;
c=(e-1000a-100b)/10;
d=(e-1000a-100b-10c);
if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d){
num=num+1;
if(num==cishu+1){
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl;
break;
}
}
e=e+1;
}
return 0;
}