#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 10000000000000000;
const int mod = 1000000007;
int test[345678];
signed main() {
	int n, cnt = 0; cin >> n;
	int res = 0;
	if (n <= 9) { cout << n << endl; return 0; }res = 9;
	if (n <= 35) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				res++; if (res == n) { cout << a << b << endl; return 0; }
			}
		}
	}res = 35;
	if (n <= 110) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					res++; if (res == n) { cout << a << b << c << endl; return 0; }
				}
			}
		}
	}res = 110;
	if (n <= 327) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						res++; if (res == n) { cout << a << b << c << d << endl; return 0; }
					}
				}
			}
		}
	}res = 327;
	if (n <= 956) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
							res++; if (res == n) { cout << a << b << c << d << e << endl; return 0; }
						}
					}
				}
			}
		}
	}res = 956;
	if (n <= 2782) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
							for (int f = max(e - 1, (long long)0); f <= min(e + 1, (long long)9); f++) {
								res++; if (res == n) { cout << a << b << c << d << e << f << endl; return 0; }
							}
						}
					}
				}
			}
		}
	}res = 2782;
	if (n <= 8089) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
							for (int f = max(e - 1, (long long)0); f <= min(e + 1, (long long)9); f++) {
								for (int g = max(f - 1, (long long)0); g <= min(f + 1, (long long)9); g++) {
									res++; if (res == n) { cout << a << b << c << d << e << f << g << endl; return 0; }
								}
							}
						}
					}
				}
			}
		}
	}res = 8089;
	if (n <= 23527) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
							for (int f = max(e - 1, (long long)0); f <= min(e + 1, (long long)9); f++) {
								for (int g = max(f - 1, (long long)0); g <= min(f + 1, (long long)9); g++) {
									for (int h = max(g - 1, (long long)0); h <= min(g + 1, (long long)9); h++) {
										res++; if (res == n) { cout << a << b << c << d << e << f << g << h << endl; return 0; }
									}
								}
							}
						}
					}
				}
			}
		}
	}res = 23527;
	if (n <= 68468) {
		for (int a = 1; a < 10; a++) {
			for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
				for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
					for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
						for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
							for (int f = max(e - 1, (long long)0); f <= min(e + 1, (long long)9); f++) {
								for (int g = max(f - 1, (long long)0); g <= min(f + 1, (long long)9); g++) {
									for (int h = max(g - 1, (long long)0); h <= min(g + 1, (long long)9); h++) {
										for (int i = max(h - 1, (long long)0); i <= min(h + 1, (long long)9); i++) {
											res++; if (res == n) { cout << a << b << c << d << e << f << g << h << i << endl; return 0; }
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}res = 68468;
	for (int a = 1; a < 10; a++) {
		for (int b = a - 1; b <= min(a + 1, (long long)9); b++) {
			for (int c = max(b - 1, (long long)0); c <= min(b + 1, (long long)9); c++) {
				for (int d = max(c - 1, (long long)0); d <= min(c + 1, (long long)9); d++) {
					for (int e = max(d - 1, (long long)0); e <= min(d + 1, (long long)9); e++) {
						for (int f = max(e - 1, (long long)0); f <= min(e + 1, (long long)9); f++) {
							for (int g = max(f - 1, (long long)0); g <= min(f + 1, (long long)9); g++) {
								for (int h = max(g - 1, (long long)0); h <= min(g + 1, (long long)9); h++) {
									for (int i = max(h - 1, (long long)0); i <= min(h + 1, (long long)9); i++) {
										for (int j = max(i - 1, (long long)0); j <= min(i + 1, (long long)9); j++) {
											res++; if (res == n) { cout << a << b << c << d << e << f << g << h << i << j << endl; return 0; }
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256