#include <stdio.h>
#include <stdbool.h>
bool different(int c1, int c2, int c3, int c4, int c5) {
    if(c1 != c2 && c1 != c3 && c1 != c4 && c1 != c5) {
        if(c2 != c3 && c2 != c4 && c2 != c5) {
            if(c3 != c4 && c3 != c5) {
                if(c4 != c5) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int k;
    if (scanf("%d", &k) != EOF) {
        int cur = 98765;
        while(k > 1) {
            cur--;
            int c1 = cur / 10000 % 10;
            int c2 = cur / 1000 % 10;
            int c3 = cur / 100 % 10;
            int c4 = cur / 10 % 10;
            int c5 = cur % 10;
            if(different(c1,c2,c3,c4,c5)) {
                k--;
            }
        }
        if(cur < 10000) {
            printf("0");
        }
        printf("%d\n", cur);
    } else {
        printf("没有输入\n");
    }
    return 0;
}