unittest
{
	assert( [ "15" ].parse.expand.solve == "23" );
	assert( [ "1" ].parse.expand.solve == "1" );
	assert( [ "13" ].parse.expand.solve == "21" );
	assert( [ "100000" ].parse.expand.solve == "3234566667" );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto k = input.front.to!( long );
	return tuple( k );
}

auto solve( long k )
{
	long[] anss;
	auto p = 0L;
	LOOP: for( auto d = 1L;; d++ )
	{
		foreach( i; 1 .. 10 )
		{
			auto pp = memoize!solve2( i, d );
			if( k <= p + pp )
			{
				anss.length = d;
				anss[ 0 ] = i;
				break LOOP;
			}
			p += pp;
		}
	}
	foreach( i, ref ans; anss )
	{
		if( i == 0 ) continue;
		foreach( j; max( 0, anss[ i - 1 ] - 1 ) .. min( 10, anss[ i - 1 ] + 2 ) )
		{
			auto pp = memoize!solve2( j, anss.length.signed - i );
			if( k <= p + pp )
			{
				ans = j;
				break;
			}
			p += pp;
		}
	}
	return anss.to!( string[] ).join( "" );
}

long solve2( long i, long d )
{
	if( d <= 1 ) return 1L;
	if( i == 0 ) return memoize!solve2( i, d - 1 ) + memoize!solve2( i + 1, d - 1 );
	if( i == 9 ) return memoize!solve2( i - 1, d - 1 ) + memoize!solve2( i, d - 1 );
	return memoize!solve2( i - 1, d - 1 ) + memoize!solve2( i, d - 1 ) + memoize!solve2( i + 1, d - 1 );
}
