//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vvvd vector<vector<vector<double>>>


#define int long long

using namespace std;


const int MAX = 510000;

ll mod_inverse(int a,int M){
	int x=M-2;
	ll temp=a;
	ll ret=1;
	//a^(MOD-1)==1(mod MOD)を利用
	//a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める

	while(x!=0){
		if(x%2==1){
			ret=(ret*temp)%M;
		}
		temp=(temp*temp)%M;
		x=x/2;
	}
	return ret;
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed compare_int(const void *a, const void *b)
{
	int *A = (int *)a;
	int *B = (int *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}

int makeTablePart(int t,int n,vi& memo,vi& table){
	int i;
	int temp=1;
	int ans=0;
	if(t==n){
		for(i=1;i<=n;i++){
			ans=ans+memo[n-i]*temp;
			temp *= 10;
		}
		table.push_back(ans);
	}else if(t==0){
		for(i=1;i<=9;i++){
			memo[0]=i;
			makeTablePart(t+1,n,memo,table);
		}
	}else{
		if(memo[t-1]!=0){
			memo[t]=memo[t-1]-1;
			makeTablePart(t+1,n,memo,table);
		}

		memo[t]=memo[t-1];
		makeTablePart(t+1,n,memo,table);

		if(memo[t-1]!=9){
			memo[t]=memo[t-1]+1;
			makeTablePart(t+1,n,memo,table);
		}
	}

	return 0;
}

int makeTable(vi& table, int n){
	vi memo(n,0);

	makeTablePart(0,n,memo,table);
	return 0;
}

signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	int x,y,z;
	static int a[200010];
	static int b[200010];
	static int v[100010];
	static int p[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	vector<int> vec;
	vector<int> vtemp;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	vvi graph;
	
	//データの読み込み


	scanf("%lld",&n);
	//scanf_s("%lld",&n);


	//scanf("%s",&s);
	//scanf_s("%s",&s,20);


	/*for(i=0;i<n;i++){
		//scanf("%d",&a[i]);
		scanf_s("%d",&a[i]);
	}*/



	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();
//	COMinit();
	vi table;

	i=1;
	while(1==1){
		makeTable(table,i);
	
		if(n<=table.size()){
			printf("%lld",table[n-1]);
			break;
		}
		i++;
	}


//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 2420