#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

bool isOK(ll N) {
    if (N == 0)
        return false;
    ll lastN = N % 10;
    N /= 10;
    while(N) {
        ll n = N % 10;
        if (abs(n-lastN) > 1)
            return false;
        lastN = n;
        N /= 10;
    }
    return true;
}

int main(void)
{
    int K;
    cin >> K;
    ll mem[1001];
    mem[0] = 0LL;
    mem[1] = 878LL;
    mem[2] = 4445LL;
    mem[3] = 8788LL;
    mem[4] = 21122LL;
    mem[5] = 33322LL;
    mem[6] = 45434LL;
    mem[7] = 56776LL;
    mem[8] = 76667LL;
    mem[9] = 88888LL;
    mem[10] = 110111LL;
    mem[11] = 122345LL;
    mem[12] = 221122LL;
    mem[13] = 233322LL;
    mem[14] = 323234LL;
    mem[15] = 343211LL;
    mem[16] = 432332LL;
    mem[17] = 444444LL;
    mem[18] = 456556LL;
    mem[19] = 545676LL;
    mem[20] = 565566LL;
    mem[21] = 655543LL;
    mem[22] = 667655LL;
    mem[23] = 765432LL;
    mem[24] = 776767LL;
    mem[25] = 788989LL;
    mem[26] = 887765LL;
    mem[27] = 987777LL;
    mem[28] = 1001012LL;
    mem[29] = 1101111LL;
    mem[30] = 1122111LL;
    mem[31] = 1212233LL;
    mem[32] = 1232232LL;
    mem[33] = 2101234LL;
    mem[34] = 2122234LL;
    mem[35] = 2221010LL;
    mem[36] = 2233211LL;
    mem[37] = 2322345LL;
    mem[38] = 2334544LL;
    mem[39] = 3210122LL;
    mem[40] = 3223212LL;
    mem[41] = 3234555LL;
    mem[42] = 3332332LL;
    mem[43] = 3344444LL;
    mem[44] = 3434343LL;
    mem[45] = 3445677LL;
    mem[46] = 4321222LL;
    mem[47] = 4333344LL;
    mem[48] = 4345456LL;
    mem[49] = 4443211LL;
    mem[50] = 4454545LL;
    mem[51] = 4544443LL;
    mem[52] = 4556555LL;
    mem[53] = 4567889LL;
    mem[54] = 5443345LL;
    mem[55] = 5455543LL;
    mem[56] = 5545433LL;
    mem[57] = 5556767LL;
    mem[58] = 5654444LL;
    mem[59] = 5666556LL;
    mem[60] = 5677899LL;
    mem[61] = 6545667LL;
    mem[62] = 6565565LL;
    mem[63] = 6655456LL;
    mem[64] = 6667654LL;
    mem[65] = 6678999LL;
    mem[66] = 6776766LL;
    mem[67] = 6788988LL;
    mem[68] = 7665434LL;
    mem[69] = 7676777LL;
    mem[70] = 7766767LL;
    mem[71] = 7778889LL;
    mem[72] = 7877666LL;
    mem[73] = 7889987LL;
    mem[74] = 8767676LL;
    mem[75] = 8787667LL;
    mem[76] = 8877789LL;
    mem[77] = 8898789LL;
    mem[78] = 8998887LL;
    mem[79] = 9887656LL;
    mem[80] = 9987676LL;
    mem[81] = 10000121LL;
    mem[82] = 10101001LL;
    mem[83] = 10121223LL;
    mem[84] = 11010111LL;
    mem[85] = 11110123LL;
    mem[86] = 11123221LL;
    mem[87] = 11221212LL;
    mem[88] = 11233334LL;
    mem[89] = 12111123LL;
    mem[90] = 12123344LL;
    mem[91] = 12222122LL;
    mem[92] = 12234321LL;
    mem[93] = 12323455LL;
    mem[94] = 12343432LL;
    mem[95] = 21010010LL;
    mem[96] = 21110101LL;
    mem[97] = 21122343LL;
    mem[98] = 21221112LL;
    mem[99] = 21233234LL;
    mem[100] = 22111101LL;
    mem[101] = 22123322LL;
    mem[102] = 22222100LL;
    mem[103] = 22233443LL;
    mem[104] = 22323433LL;
    mem[105] = 22343332LL;
    mem[106] = 23211223LL;
    mem[107] = 23223444LL;
    mem[108] = 23321212LL;
    mem[109] = 23333334LL;
    mem[110] = 23345454LL;
    mem[111] = 23434567LL;
    mem[112] = 23454543LL;
    mem[113] = 32110010LL;
    mem[114] = 32122323LL;
    mem[115] = 32221100LL;
    mem[116] = 32233222LL;
    mem[117] = 32323212LL;
    mem[118] = 32334555LL;
    mem[119] = 33211001LL;
    mem[120] = 33223223LL;
    mem[121] = 33234566LL;
    mem[122] = 33332343LL;
    mem[123] = 33344455LL;
    mem[124] = 33434432LL;
    mem[125] = 33454322LL;
    mem[126] = 34321233LL;
    mem[127] = 34333433LL;
    mem[128] = 34345545LL;
    mem[129] = 34443222LL;
    mem[130] = 34454556LL;
    mem[131] = 34544454LL;
    mem[132] = 34556566LL;
    mem[133] = 43210000LL;
    mem[134] = 43222321LL;
    mem[135] = 43234434LL;
    mem[136] = 43332211LL;
    mem[137] = 43344323LL;
    mem[138] = 43433444LL;
    mem[139] = 43445556LL;
    mem[140] = 44321101LL;
    mem[141] = 44333223LL;
    mem[142] = 44344565LL;
    mem[143] = 44434456LL;
    mem[144] = 44454432LL;
    mem[145] = 44544322LL;
    mem[146] = 44555656LL;
    mem[147] = 44567776LL;
    mem[148] = 45443232LL;
    mem[149] = 45454566LL;
    mem[150] = 45544456LL;
    mem[151] = 45556654LL;
    mem[152] = 45654323LL;
    mem[153] = 45665665LL;
    mem[154] = 45677778LL;
    mem[155] = 54323432LL;
    mem[156] = 54343323LL;
    mem[157] = 54433222LL;
    mem[158] = 54444556LL;
    mem[159] = 54456676LL;
    mem[160] = 54554344LL;
    mem[161] = 54565678LL;
    mem[162] = 55433434LL;
    mem[163] = 55445554LL;
    mem[164] = 55543222LL;
    mem[165] = 55554556LL;
    mem[166] = 55566676LL;
    mem[167] = 55656567LL;
    mem[168] = 55676544LL;
    mem[169] = 56543456LL;
    mem[170] = 56555654LL;
    mem[171] = 56567766LL;
    mem[172] = 56665443LL;
    mem[173] = 56676778LL;
    mem[174] = 56766776LL;
    mem[175] = 56778898LL;
    mem[176] = 65433232LL;
    mem[177] = 65444566LL;
    mem[178] = 65456678LL;
    mem[179] = 65554432LL;
    mem[180] = 65566544LL;
    mem[181] = 65655665LL;
    mem[182] = 65667777LL;
    mem[183] = 66543332LL;
    mem[184] = 66555444LL;
    mem[185] = 66566778LL;
    mem[186] = 66656677LL;
    mem[187] = 66676654LL;
    mem[188] = 66766566LL;
    mem[189] = 66778766LL;
    mem[190] = 67654543LL;
    mem[191] = 67666655LL;
    mem[192] = 67678777LL;
    mem[193] = 67776545LL;
    mem[194] = 67788766LL;
    mem[195] = 67878888LL;
    mem[196] = 67899987LL;
    mem[197] = 76554445LL;
    mem[198] = 76566565LL;
    mem[199] = 76655678LL;
    mem[200] = 76667876LL;
    mem[201] = 76765567LL;
    mem[202] = 76777766LL;
    mem[203] = 77654322LL;
    mem[204] = 77665656LL;
    mem[205] = 77677777LL;
    mem[206] = 77767767LL;
    mem[207] = 77787766LL;
    mem[208] = 77877888LL;
    mem[209] = 77898888LL;
    mem[210] = 78767898LL;
    mem[211] = 78787889LL;
    mem[212] = 78878876LL;
    mem[213] = 78899888LL;
    mem[214] = 78999987LL;
    mem[215] = 87665556LL;
    mem[216] = 87677677LL;
    mem[217] = 87767667LL;
    mem[218] = 87787666LL;
    mem[219] = 87877788LL;
    mem[220] = 87898788LL;
    mem[221] = 88767876LL;
    mem[222] = 88787789LL;
    mem[223] = 88878776LL;
    mem[224] = 88898998LL;
    mem[225] = 88999878LL;
    mem[226] = 89887778LL;
    mem[227] = 89987876LL;
    mem[228] = 98765666LL;
    mem[229] = 98777787LL;
    mem[230] = 98876565LL;
    mem[231] = 98888778LL;
    mem[232] = 98988876LL;
    mem[233] = 99877776LL;
    mem[234] = 99898776LL;
    mem[235] = 99998788LL;
    mem[236] = 100012110LL;
    mem[237] = 100112122LL;
    mem[238] = 101000100LL;
    mem[239] = 101100112LL;
    mem[240] = 101121210LL;
    mem[241] = 101212111LL;
    mem[242] = 101232110LL;
    mem[243] = 110001112LL;
    mem[244] = 110101210LL;
    mem[245] = 110122210LL;
    mem[246] = 111011110LL;
    mem[247] = 111111122LL;
    mem[248] = 111123343LL;
    mem[249] = 111222121LL;
    mem[250] = 111233456LL;
    mem[251] = 112112110LL;
    mem[252] = 112210001LL;
    mem[253] = 112222322LL;
    mem[254] = 112234443LL;
    mem[255] = 112332212LL;
    mem[256] = 112344332LL;
    mem[257] = 121011001LL;
    mem[258] = 121111100LL;
    mem[259] = 121123321LL;
    mem[260] = 121221234LL;
    mem[261] = 121233434LL;
    mem[262] = 122111223LL;
    mem[263] = 122123444LL;
    mem[264] = 122222222LL;
    mem[265] = 122234343LL;
    mem[266] = 122332112LL;
    mem[267] = 122343454LL;
    mem[268] = 123212210LL;
    mem[269] = 123232123LL;
    mem[270] = 123322121LL;
    mem[271] = 123333456LL;
    mem[272] = 123345654LL;
    mem[273] = 123443323LL;
    mem[274] = 123455443LL;
    mem[275] = 210011001LL;
    mem[276] = 210111100LL;
    mem[277] = 210123321LL;
    mem[278] = 211012222LL;
    mem[279] = 211112234LL;
    mem[280] = 211211010LL;
    mem[281] = 211223232LL;
    mem[282] = 211234567LL;
    mem[283] = 212121011LL;
    mem[284] = 212211212LL;
    mem[285] = 212223433LL;
    mem[286] = 212321123LL;
    mem[287] = 212333323LL;
    mem[288] = 212345443LL;
    mem[289] = 221012122LL;
    mem[290] = 221112212LL;
    mem[291] = 221210112LL;
    mem[292] = 221223210LL;
    mem[293] = 221234545LL;
    mem[294] = 222112343LL;
    mem[295] = 222211112LL;
    mem[296] = 222223333LL;
    mem[297] = 222321101LL;
    mem[298] = 222333223LL;
    mem[299] = 222344565LL;
    mem[300] = 223221112LL;
    mem[301] = 223233234LL;
    mem[302] = 223323232LL;
    mem[303] = 223334567LL;
    mem[304] = 223432322LL;
    mem[305] = 223444434LL;
    mem[306] = 223456554LL;
    mem[307] = 232112122LL;
    mem[308] = 232210100LL;
    mem[309] = 232222334LL;
    mem[310] = 232234455LL;
    mem[311] = 232332232LL;
    mem[312] = 232344344LL;
    mem[313] = 233212322LL;
    mem[314] = 233232321LL;
    mem[315] = 233322233LL;
    mem[316] = 233334432LL;
    mem[317] = 233432101LL;
    mem[318] = 233443443LL;
    mem[319] = 233455555LL;
    mem[320] = 234323323LL;
    mem[321] = 234343222LL;
    mem[322] = 234432343LL;
    mem[323] = 234444455LL;
    mem[324] = 234456567LL;
    mem[325] = 234554321LL;
    mem[326] = 234565655LL;
    mem[327] = 321010012LL;
    mem[328] = 321110111LL;
    mem[329] = 321122345LL;
    mem[330] = 321221122LL;
    mem[331] = 321233322LL;
    mem[332] = 322111111LL;
    mem[333] = 322123332LL;
    mem[334] = 322222110LL;
    mem[335] = 322233445LL;
    mem[336] = 322323443LL;
    mem[337] = 322343334LL;
    mem[338] = 323211233LL;
    mem[339] = 323223454LL;
    mem[340] = 323321222LL;
    mem[341] = 323333344LL;
    mem[342] = 323345456LL;
    mem[343] = 323443211LL;
    mem[344] = 323454545LL;
    mem[345] = 332110012LL;
    mem[346] = 332122333LL;
    mem[347] = 332221110LL;
    mem[348] = 332233232LL;
    mem[349] = 332323222LL;
    mem[350] = 332334565LL;
    mem[351] = 333211011LL;
    mem[352] = 333223233LL;
    mem[353] = 333321000LL;
    mem[354] = 333332345LL;
    mem[355] = 333344543LL;
    mem[356] = 333434434LL;
    mem[357] = 333454332LL;
    mem[358] = 334322100LL;
    mem[359] = 334333443LL;
    mem[360] = 334345555LL;
    mem[361] = 334443232LL;
    mem[362] = 334454566LL;
    mem[363] = 334544456LL;
    mem[364] = 334556654LL;
    mem[365] = 343210010LL;
    mem[366] = 343222323LL;
    mem[367] = 343234444LL;
    mem[368] = 343332221LL;
    mem[369] = 343344333LL;
    mem[370] = 343433454LL;
    mem[371] = 343445566LL;
    mem[372] = 344321111LL;
    mem[373] = 344333233LL;
    mem[374] = 344344567LL;
    mem[375] = 344434544LL;
    mem[376] = 344454434LL;
    mem[377] = 344544332LL;
    mem[378] = 344555666LL;
    mem[379] = 344567778LL;
    mem[380] = 345443234LL;
    mem[381] = 345455432LL;
    mem[382] = 345544544LL;
    mem[383] = 345556656LL;
    mem[384] = 345654333LL;
    mem[385] = 345665667LL;
    mem[386] = 345677788LL;
    mem[387] = 432111233LL;
    mem[388] = 432123454LL;
    mem[389] = 432222232LL;
    mem[390] = 432234345LL;
    mem[391] = 432332122LL;
    mem[392] = 432343456LL;
    mem[393] = 433212212LL;
    mem[394] = 433232211LL;
    mem[395] = 433322123LL;
    mem[396] = 433334322LL;
    mem[397] = 433345656LL;
    mem[398] = 433443333LL;
    mem[399] = 433455445LL;
    mem[400] = 434323221LL;
    mem[401] = 434334556LL;
    mem[402] = 434432233LL;
    mem[403] = 434444345LL;
    mem[404] = 434456543LL;
    mem[405] = 434545655LL;
    mem[406] = 434565545LL;
    mem[407] = 443211223LL;
    mem[408] = 443223444LL;
    mem[409] = 443321212LL;
    mem[410] = 443333334LL;
    mem[411] = 443345454LL;
    mem[412] = 443434567LL;
    mem[413] = 443454543LL;
    mem[414] = 444322233LL;
    mem[415] = 444334432LL;
    mem[416] = 444432101LL;
    mem[417] = 444443443LL;
    mem[418] = 444455555LL;
    mem[419] = 444545445LL;
    mem[420] = 444556787LL;
    mem[421] = 445432321LL;
    mem[422] = 445444433LL;
    mem[423] = 445456545LL;
    mem[424] = 445545665LL;
    mem[425] = 445565555LL;
    mem[426] = 445655454LL;
    mem[427] = 445666788LL;
    mem[428] = 445678989LL;
    mem[429] = 454332334LL;
    mem[430] = 454344454LL;
    mem[431] = 454434345LL;
    mem[432] = 454454321LL;
    mem[433] = 454543433LL;
    mem[434] = 454555545LL;
    mem[435] = 454567665LL;
    mem[436] = 455434565LL;
    mem[437] = 455454455LL;
    mem[438] = 455544345LL;
    mem[439] = 455556543LL;
    mem[440] = 455567877LL;
    mem[441] = 455665554LL;
    mem[442] = 455677667LL;
    mem[443] = 456545443LL;
    mem[444] = 456556777LL;
    mem[445] = 456654454LL;
    mem[446] = 456666566LL;
    mem[447] = 456678766LL;
    mem[448] = 456767899LL;
    mem[449] = 456787898LL;
    mem[450] = 543221010LL;
    mem[451] = 543233211LL;
    mem[452] = 543322345LL;
    mem[453] = 543334544LL;
    mem[454] = 543432221LL;
    mem[455] = 543444333LL;
    mem[456] = 543455667LL;
    mem[457] = 544323443LL;
    mem[458] = 544343334LL;
    mem[459] = 544433233LL;
    mem[460] = 544444567LL;
    mem[461] = 544456765LL;
    mem[462] = 544554433LL;
    mem[463] = 544566545LL;
    mem[464] = 545433445LL;
    mem[465] = 545445565LL;
    mem[466] = 545543233LL;
    mem[467] = 545554567LL;
    mem[468] = 545566765LL;
    mem[469] = 545656656LL;
    mem[470] = 545676555LL;
    mem[471] = 554322123LL;
    mem[472] = 554334322LL;
    mem[473] = 554345656LL;
    mem[474] = 554443333LL;
    mem[475] = 554455445LL;
    mem[476] = 554544565LL;
    mem[477] = 554556677LL;
    mem[478] = 555432211LL;
    mem[479] = 555444323LL;
    mem[480] = 555455665LL;
    mem[481] = 555545555LL;
    mem[482] = 555565445LL;
    mem[483] = 555654566LL;
    mem[484] = 555666678LL;
    mem[485] = 555678878LL;
    mem[486] = 556554345LL;
    mem[487] = 556566543LL;
    mem[488] = 556655656LL;
    mem[489] = 556667776LL;
    mem[490] = 556765545LL;
    mem[491] = 556777666LL;
    mem[492] = 556789987LL;
    mem[493] = 565443343LL;
    mem[494] = 565455455LL;
    mem[495] = 565544567LL;
    mem[496] = 565556765LL;
    mem[497] = 565654434LL;
    mem[498] = 565666554LL;
    mem[499] = 565677889LL;
    mem[500] = 566545665LL;
    mem[501] = 566565555LL;
    mem[502] = 566655454LL;
    mem[503] = 566666788LL;
    mem[504] = 566678989LL;
    mem[505] = 566776678LL;
    mem[506] = 566788899LL;
    mem[507] = 567665432LL;
    mem[508] = 567676767LL;
    mem[509] = 567766765LL;
    mem[510] = 567778887LL;
    mem[511] = 567877656LL;
    mem[512] = 567889898LL;
    mem[513] = 654323322LL;
    mem[514] = 654343221LL;
    mem[515] = 654432334LL;
    mem[516] = 654444454LL;
    mem[517] = 654456566LL;
    mem[518] = 654545678LL;
    mem[519] = 654565654LL;
    mem[520] = 655433332LL;
    mem[521] = 655445444LL;
    mem[522] = 655456778LL;
    mem[523] = 655554454LL;
    mem[524] = 655566566LL;
    mem[525] = 655656543LL;
    mem[526] = 655667877LL;
    mem[527] = 656543432LL;
    mem[528] = 656555544LL;
    mem[529] = 656567656LL;
    mem[530] = 656656777LL;
    mem[531] = 656676676LL;
    mem[532] = 656766666LL;
    mem[533] = 656778788LL;
    mem[534] = 665432344LL;
    mem[535] = 665444456LL;
    mem[536] = 665456654LL;
    mem[537] = 665554322LL;
    mem[538] = 665565656LL;
    mem[539] = 665655555LL;
    mem[540] = 665667667LL;
    mem[541] = 666543222LL;
    mem[542] = 666554556LL;
    mem[543] = 666566676LL;
    mem[544] = 666656567LL;
    mem[545] = 666676544LL;
    mem[546] = 666765678LL;
    mem[547] = 666777877LL;
    mem[548] = 667654433LL;
    mem[549] = 667666545LL;
    mem[550] = 667677888LL;
    mem[551] = 667767878LL;
    mem[552] = 667787877LL;
    mem[553] = 667878778LL;
    mem[554] = 667899876LL;
    mem[555] = 676554343LL;
    mem[556] = 676565677LL;
    mem[557] = 676655654LL;
    mem[558] = 676667766LL;
    mem[559] = 676765543LL;
    mem[560] = 676777656LL;
    mem[561] = 676789898LL;
    mem[562] = 677665554LL;
    mem[563] = 677677667LL;
    mem[564] = 677767665LL;
    mem[565] = 677787656LL;
    mem[566] = 677877778LL;
    mem[567] = 677898778LL;
    mem[568] = 678767788LL;
    mem[569] = 678787787LL;
    mem[570] = 678878766LL;
    mem[571] = 678898988LL;
    mem[572] = 678999876LL;
    mem[573] = 765443233LL;
    mem[574] = 765454567LL;
    mem[575] = 765544543LL;
    mem[576] = 765556655LL;
    mem[577] = 765654332LL;
    mem[578] = 765665666LL;
    mem[579] = 765677787LL;
    mem[580] = 766545555LL;
    mem[581] = 766565445LL;
    mem[582] = 766654566LL;
    mem[583] = 766666678LL;
    mem[584] = 766678878LL;
    mem[585] = 766776654LL;
    mem[586] = 766788789LL;
    mem[587] = 767656766LL;
    mem[588] = 767676665LL;
    mem[589] = 767766655LL;
    mem[590] = 767778777LL;
    mem[591] = 767876776LL;
    mem[592] = 767888998LL;
    mem[593] = 776544556LL;
    mem[594] = 776556676LL;
    mem[595] = 776654345LL;
    mem[596] = 776666543LL;
    mem[597] = 776677878LL;
    mem[598] = 776767876LL;
    mem[599] = 776787789LL;
    mem[600] = 777656545LL;
    mem[601] = 777667887LL;
    mem[602] = 777765656LL;
    mem[603] = 777777777LL;
    mem[604] = 777876555LL;
    mem[605] = 777888776LL;
    mem[606] = 778766565LL;
    mem[607] = 778778765LL;
    mem[608] = 778876678LL;
    mem[609] = 778888899LL;
    mem[610] = 778988998LL;
    mem[611] = 787655667LL;
    mem[612] = 787667787LL;
    mem[613] = 787765556LL;
    mem[614] = 787777677LL;
    mem[615] = 787789998LL;
    mem[616] = 787887889LL;
    mem[617] = 788766543LL;
    mem[618] = 788777878LL;
    mem[619] = 788876656LL;
    mem[620] = 788888877LL;
    mem[621] = 788988889LL;
    mem[622] = 789877789LL;
    mem[623] = 789898789LL;
    mem[624] = 789998887LL;
    mem[625] = 876545667LL;
    mem[626] = 876565565LL;
    mem[627] = 876655456LL;
    mem[628] = 876667654LL;
    mem[629] = 876678999LL;
    mem[630] = 876776766LL;
    mem[631] = 876788988LL;
    mem[632] = 877665434LL;
    mem[633] = 877676777LL;
    mem[634] = 877766767LL;
    mem[635] = 877778889LL;
    mem[636] = 877877666LL;
    mem[637] = 877889987LL;
    mem[638] = 878767676LL;
    mem[639] = 878787667LL;
    mem[640] = 878877789LL;
    mem[641] = 878898789LL;
    mem[642] = 878998887LL;
    mem[643] = 887656778LL;
    mem[644] = 887676677LL;
    mem[645] = 887766667LL;
    mem[646] = 887778789LL;
    mem[647] = 887876788LL;
    mem[648] = 887889878LL;
    mem[649] = 888767654LL;
    mem[650] = 888778999LL;
    mem[651] = 888877767LL;
    mem[652] = 888898767LL;
    mem[653] = 888998787LL;
    mem[654] = 889878988LL;
    mem[655] = 889987654LL;
    mem[656] = 898765444LL;
    mem[657] = 898776787LL;
    mem[658] = 898789877LL;
    mem[659] = 898887777LL;
    mem[660] = 898987789LL;
    mem[661] = 899876776LL;
    mem[662] = 899888998LL;
    mem[663] = 899989878LL;
    mem[664] = 987656543LL;
    mem[665] = 987667877LL;
    mem[666] = 987765654LL;
    mem[667] = 987777767LL;
    mem[668] = 987876545LL;
    mem[669] = 987888766LL;
    mem[670] = 988766555LL;
    mem[671] = 988777898LL;
    mem[672] = 988876676LL;
    mem[673] = 988888889LL;
    mem[674] = 988988988LL;
    mem[675] = 989877887LL;
    mem[676] = 989898887LL;
    mem[677] = 989998899LL;
    mem[678] = 998776544LL;
    mem[679] = 998788765LL;
    mem[680] = 998878887LL;
    mem[681] = 998899899LL;
    mem[682] = 998999998LL;
    mem[683] = 999887889LL;
    mem[684] = 999988766LL;
    mem[685] = 1000001223LL;
    mem[686] = 1000110000LL;
    mem[687] = 1000122321LL;
    mem[688] = 1001011221LL;
    mem[689] = 1001111233LL;
    mem[690] = 1001123454LL;
    mem[691] = 1001222232LL;
    mem[692] = 1001234345LL;
    mem[693] = 1010012221LL;
    mem[694] = 1010112233LL;
    mem[695] = 1011001001LL;
    mem[696] = 1011101100LL;
    mem[697] = 1011122100LL;
    mem[698] = 1011212222LL;
    mem[699] = 1011232221LL;
    mem[700] = 1012101223LL;
    mem[701] = 1012122223LL;
    mem[702] = 1012212345LL;
    mem[703] = 1012232344LL;
    mem[704] = 1012322334LL;
    mem[705] = 1012334455LL;
    mem[706] = 1100000111LL;
    mem[707] = 1100100123LL;
    mem[708] = 1100121221LL;
    mem[709] = 1101010101LL;
    mem[710] = 1101110121LL;
    mem[711] = 1101123211LL;
    mem[712] = 1101221210LL;
    mem[713] = 1101233332LL;
    mem[714] = 1110011121LL;
    mem[715] = 1110111211LL;
    mem[716] = 1110123432LL;
    mem[717] = 1111012333LL;
    mem[718] = 1111112345LL;
    mem[719] = 1111211122LL;
    mem[720] = 1111223343LL;
    mem[721] = 1112100111LL;
    mem[722] = 1112121123LL;
    mem[723] = 1112212110LL;
    mem[724] = 1112232101LL;
    mem[725] = 1112321234LL;
    mem[726] = 1112333434LL;
    mem[727] = 1112345554LL;
    mem[728] = 1121012233LL;
    mem[729] = 1121112323LL;
    mem[730] = 1121211100LL;
    mem[731] = 1121223321LL;
    mem[732] = 1122100010LL;
    mem[733] = 1122121101LL;
    mem[734] = 1122211223LL;
    mem[735] = 1122223444LL;
    mem[736] = 1122321212LL;
    mem[737] = 1122333334LL;
    mem[738] = 1122345454LL;
    mem[739] = 1123221223LL;
    mem[740] = 1123233345LL;
    mem[741] = 1123323343LL;
    mem[742] = 1123343234LL;
    mem[743] = 1123433211LL;
    mem[744] = 1123444545LL;
    mem[745] = 1123456665LL;
    mem[746] = 1210012233LL;
    mem[747] = 1210112323LL;
    mem[748] = 1211001100LL;
    mem[749] = 1211101112LL;
    mem[750] = 1211122112LL;
    mem[751] = 1211212234LL;
    mem[752] = 1211232233LL;
    mem[753] = 1212110000LL;
    mem[754] = 1212122321LL;
    mem[755] = 1212221011LL;
    mem[756] = 1212233212LL;
    mem[757] = 1212323210LL;
    mem[758] = 1212334545LL;
    mem[759] = 1221000123LL;
    mem[760] = 1221101011LL;
    mem[761] = 1221121233LL;
    mem[762] = 1221212212LL;
    mem[763] = 1221232211LL;
    mem[764] = 1222101221LL;
    mem[765] = 1222122221LL;
    mem[766] = 1222212343LL;
    mem[767] = 1222232334LL;
    mem[768] = 1222322332LL;
    mem[769] = 1222334445LL;
    mem[770] = 1223210101LL;
    mem[771] = 1223222343LL;
    mem[772] = 1223234456LL;
    mem[773] = 1223332233LL;
    mem[774] = 1223344345LL;
    mem[775] = 1223434322LL;
    mem[776] = 1223445656LL;
    mem[777] = 1232100123LL;
    mem[778] = 1232121221LL;
    mem[779] = 1232212122LL;
    mem[780] = 1232232121LL;
    mem[781] = 1232322111LL;
    mem[782] = 1232333454LL;
    mem[783] = 1232345566LL;
    mem[784] = 1233222122LL;
    mem[785] = 1233234321LL;
    mem[786] = 1233323455LL;
    mem[787] = 1233343432LL;
    mem[788] = 1233433323LL;
    mem[789] = 1233445443LL;
    mem[790] = 1233456777LL;
    mem[791] = 1234332332LL;
    mem[792] = 1234344444LL;
    mem[793] = 1234434343LL;
    mem[794] = 1234445677LL;
    mem[795] = 1234543345LL;
    mem[796] = 1234555543LL;
    mem[797] = 1234567655LL;
    mem[798] = 2100012121LL;
    mem[799] = 2100112211LL;
    mem[800] = 2101000111LL;
    mem[801] = 2101100123LL;
    mem[802] = 2101121221LL;
    mem[803] = 2101212122LL;
    mem[804] = 2101232121LL;
    mem[805] = 2110001123LL;
    mem[806] = 2110101221LL;
    mem[807] = 2110122221LL;
    mem[808] = 2111011121LL;
    mem[809] = 2111111211LL;
    mem[810] = 2111123432LL;
    mem[811] = 2111222210LL;
    mem[812] = 2111234323LL;
    mem[813] = 2112112121LL;
    mem[814] = 2112210012LL;
    mem[815] = 2112222333LL;
    mem[816] = 2112234454LL;
    mem[817] = 2112332223LL;
    mem[818] = 2112344343LL;
    mem[819] = 2121011012LL;
    mem[820] = 2121111111LL;
    mem[821] = 2121123332LL;
    mem[822] = 2121222110LL;
    mem[823] = 2121233445LL;
    mem[824] = 2122111234LL;
    mem[825] = 2122123455LL;
    mem[826] = 2122222233LL;
    mem[827] = 2122234432LL;
    mem[828] = 2122332123LL;
    mem[829] = 2122344321LL;
    mem[830] = 2123212221LL;
    mem[831] = 2123232212LL;
    mem[832] = 2123322210LL;
    mem[833] = 2123334323LL;
    mem[834] = 2123345665LL;
    mem[835] = 2123443334LL;
    mem[836] = 2123455454LL;
    mem[837] = 2210011012LL;
    mem[838] = 2210111111LL;
    mem[839] = 2210123332LL;
    mem[840] = 2211012233LL;
    mem[841] = 2211112323LL;
    mem[842] = 2211211100LL;
    mem[843] = 2211223321LL;
    mem[844] = 2212100010LL;
    mem[845] = 2212121101LL;
    mem[846] = 2212211223LL;
    mem[847] = 2212223444LL;
    mem[848] = 2212321212LL;
    mem[849] = 2212333334LL;
    mem[850] = 2212345454LL;
    mem[851] = 2221012211LL;
    mem[852] = 2221112223LL;
    mem[853] = 2221210123LL;
    mem[854] = 2221223221LL;
    mem[855] = 2221234556LL;
    mem[856] = 2222121000LL;
    mem[857] = 2222211123LL;
    mem[858] = 2222223344LL;
    mem[859] = 2222321112LL;
    mem[860] = 2222333234LL;
    mem[861] = 2222345432LL;
    mem[862] = 2223221123LL;
    mem[863] = 2223233323LL;
    mem[864] = 2223323321LL;
    mem[865] = 2223343212LL;
    mem[866] = 2223432333LL;
    mem[867] = 2223444445LL;
    mem[868] = 2223456565LL;
    mem[869] = 2232112211LL;
    mem[870] = 2232210111LL;
    mem[871] = 2232222345LL;
    mem[872] = 2232234544LL;
    mem[873] = 2232332321LL;
    mem[874] = 2232344433LL;
    mem[875] = 2233212333LL;
    mem[876] = 2233232332LL;
    mem[877] = 2233322322LL;
    mem[878] = 2233334443LL;
    mem[879] = 2233432112LL;
    mem[880] = 2233443454LL;
    mem[881] = 2233455566LL;
    mem[882] = 2234323334LL;
    mem[883] = 2234343233LL;
    mem[884] = 2234433210LL;
    mem[885] = 2234444544LL;
    mem[886] = 2234456656LL;
    mem[887] = 2234554332LL;
    mem[888] = 2234565666LL;
    mem[889] = 2321010110LL;
    mem[890] = 2321110122LL;
    mem[891] = 2321123212LL;
    mem[892] = 2321221211LL;
    mem[893] = 2321233333LL;
    mem[894] = 2322111122LL;
    mem[895] = 2322123343LL;
    mem[896] = 2322222121LL;
    mem[897] = 2322233456LL;
    mem[898] = 2322323454LL;
    mem[899] = 2322343345LL;
    mem[900] = 2323212101LL;
    mem[901] = 2323232100LL;
    mem[902] = 2323321233LL;
    mem[903] = 2323333433LL;
    mem[904] = 2323345545LL;
    mem[905] = 2323443222LL;
    mem[906] = 2323454556LL;
    mem[907] = 2332110110LL;
    mem[908] = 2332122344LL;
    mem[909] = 2332221121LL;
    mem[910] = 2332233321LL;
    mem[911] = 2332323233LL;
    mem[912] = 2332343210LL;
    mem[913] = 2333211101LL;
    mem[914] = 2333223322LL;
    mem[915] = 2333321011LL;
    mem[916] = 2333333212LL;
    mem[917] = 2333344554LL;
    mem[918] = 2333434445LL;
    mem[919] = 2333454343LL;
    mem[920] = 2334322111LL;
    mem[921] = 2334333454LL;
    mem[922] = 2334345566LL;
    mem[923] = 2334443321LL;
    mem[924] = 2334455433LL;
    mem[925] = 2334544545LL;
    mem[926] = 2334556665LL;
    mem[927] = 2343210100LL;
    mem[928] = 2343222334LL;
    mem[929] = 2343234455LL;
    mem[930] = 2343332232LL;
    mem[931] = 2343344344LL;
    mem[932] = 2343434321LL;
    mem[933] = 2343445655LL;
    mem[934] = 2344321122LL;
    mem[935] = 2344333322LL;
    mem[936] = 2344345434LL;
    mem[937] = 2344434555LL;
    mem[938] = 2344454445LL;
    mem[939] = 2344544343LL;
    mem[940] = 2344555677LL;
    mem[941] = 2344567789LL;
    mem[942] = 2345443323LL;
    mem[943] = 2345455443LL;
    mem[944] = 2345544555LL;
    mem[945] = 2345556667LL;
    mem[946] = 2345654344LL;
    mem[947] = 2345665678LL;
    mem[948] = 2345677877LL;
    mem[949] = 3210012101LL;
    mem[950] = 3210112121LL;
    mem[951] = 3211000012LL;
    mem[952] = 3211100111LL;
    mem[953] = 3211121123LL;
    mem[954] = 3211212110LL;
    mem[955] = 3211232101LL;
    mem[956] = 3212101111LL;
    mem[957] = 3212122111LL;
    mem[958] = 3212212233LL;
    mem[959] = 3212232232LL;
    mem[960] = 3212322222LL;
    mem[961] = 3212334343LL;
    mem[962] = 3212345677LL;
    mem[963] = 3221100010LL;
    mem[964] = 3221121101LL;
    mem[965] = 3221211223LL;
    mem[966] = 3221223444LL;
    mem[967] = 3222101010LL;
    mem[968] = 3222121232LL;
    mem[969] = 3222212211LL;
    mem[970] = 3222232210LL;
    mem[971] = 3222322122LL;
    mem[972] = 3222334321LL;
    mem[973] = 3222345655LL;
    mem[974] = 3223222211LL;
    mem[975] = 3223234332LL;
    mem[976] = 3223332101LL;
    mem[977] = 3223343443LL;
    mem[978] = 3223433334LL;
    mem[979] = 3223445454LL;
    mem[980] = 3223456788LL;
    mem[981] = 3232121010LL;
    mem[982] = 3232211211LL;
    mem[983] = 3232223432LL;
    mem[984] = 3232321122LL;
    mem[985] = 3232333322LL;
    mem[986] = 3232345434LL;
    mem[987] = 3233221211LL;
    mem[988] = 3233233333LL;
    mem[989] = 3233323323LL;
    mem[990] = 3233343222LL;
    mem[991] = 3233432343LL;
    mem[992] = 3233444455LL;
    mem[993] = 3233456567LL;
    mem[994] = 3234332122LL;
    mem[995] = 3234343456LL;
    mem[996] = 3234433433LL;
    mem[997] = 3234445545LL;
    mem[998] = 3234543221LL;
    mem[999] = 3234554555LL;
    mem[1000] = 3234566667LL;

    ll N = mem[K/100];
    K -= (K/100)*100;
    while(K) {
        N++;
        if (isOK(N)) --K;
    }
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 3624