public class Test {
public static void main(String[] args) {
prints(0, 0, 0, 0, 0);
}
public static void prints(int k1,int k2,int k3,int k4,int k5){
if(k5!=0){
System.out.println(k1*10000+k2*1000+k3*100+k4*10+k5);
}
for(int i=1;i<=5;i++){
if(k1==0) prints(i,k2,k3,k4,k5);
else if(k2==0){
if(i==k1) continue;
else prints(k1,i,k3,k4,k5);
}
else if(k3==0){
if(i==k2||i==k1) continue;
else prints(k1,k2,i,k4,k5);
}
else if(k4==0){
if(i==k3||i==k2||i==k1) continue;
else prints(k1,k2,k3,i,k5);
}
else if(k5==0){
if(i==k4||i==k3||i==k2||i==k1) continue;
else prints(k1,k2,k3,k4,i);
}
}
}
}