Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

<image>

The problem is: 

You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

If we sort all lucky numbers in increasing order, what's the 1-based index of n? 

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Examples

Input

4


Output

1


Input

7


Output

2


Input

77


Output

6
#include <bits/stdc++.h>
using namespace std;
int arr[1000009];
int main() {
  arr[1] = 4;
  arr[2] = 7;
  arr[3] = 44;
  arr[4] = 47;
  arr[5] = 74;
  arr[6] = 77;
  arr[7] = 444;
  arr[8] = 447;
  arr[9] = 474;
  arr[10] = 477;
  arr[11] = 744;
  arr[12] = 747;
  arr[13] = 774;
  arr[14] = 777;
  arr[15] = 4444;
  arr[16] = 4447;
  arr[17] = 4474;
  arr[18] = 4477;
  arr[19] = 4744;
  arr[20] = 4747;
  arr[21] = 4774;
  arr[22] = 4777;
  arr[23] = 7444;
  arr[24] = 7447;
  arr[25] = 7474;
  arr[26] = 7477;
  arr[27] = 7744;
  arr[28] = 7747;
  arr[29] = 7774;
  arr[30] = 7777;
  arr[31] = 44444;
  arr[32] = 44447;
  arr[33] = 44474;
  arr[34] = 44477;
  arr[35] = 44744;
  arr[36] = 44747;
  arr[37] = 44774;
  arr[38] = 44777;
  arr[39] = 47444;
  arr[40] = 47447;
  arr[41] = 47474;
  arr[42] = 47477;
  arr[43] = 47744;
  arr[44] = 47747;
  arr[45] = 47774;
  arr[46] = 47777;
  arr[47] = 74444;
  arr[48] = 74447;
  arr[49] = 74474;
  arr[50] = 74477;
  arr[51] = 74744;
  arr[52] = 74747;
  arr[53] = 74774;
  arr[54] = 74777;
  arr[55] = 77444;
  arr[56] = 77447;
  arr[57] = 77474;
  arr[58] = 77477;
  arr[59] = 77744;
  arr[60] = 77747;
  arr[61] = 77774;
  arr[62] = 77777;
  arr[63] = 444444;
  arr[64] = 444447;
  arr[65] = 444474;
  arr[66] = 444477;
  arr[67] = 444744;
  arr[68] = 444747;
  arr[69] = 444774;
  arr[70] = 444777;
  arr[71] = 447444;
  arr[72] = 447447;
  arr[73] = 447474;
  arr[74] = 447477;
  arr[75] = 447744;
  arr[76] = 447747;
  arr[77] = 447774;
  arr[78] = 447777;
  arr[79] = 474444;
  arr[80] = 474447;
  arr[81] = 474474;
  arr[82] = 474477;
  arr[83] = 474744;
  arr[84] = 474747;
  arr[85] = 474774;
  arr[86] = 474777;
  arr[87] = 477444;
  arr[88] = 477447;
  arr[89] = 477474;
  arr[90] = 477477;
  arr[91] = 477744;
  arr[92] = 477747;
  arr[93] = 477774;
  arr[94] = 477777;
  arr[95] = 744444;
  arr[96] = 744447;
  arr[97] = 744474;
  arr[98] = 744477;
  arr[99] = 744744;
  arr[100] = 744747;
  arr[101] = 744774;
  arr[102] = 744777;
  arr[103] = 747444;
  arr[104] = 747447;
  arr[105] = 747474;
  arr[106] = 747477;
  arr[107] = 747744;
  arr[108] = 747747;
  arr[109] = 747774;
  arr[110] = 747777;
  arr[111] = 774444;
  arr[112] = 774447;
  arr[113] = 774474;
  arr[114] = 774477;
  arr[115] = 774744;
  arr[116] = 774747;
  arr[117] = 774774;
  arr[118] = 774777;
  arr[119] = 777444;
  arr[120] = 777447;
  arr[121] = 777474;
  arr[122] = 777477;
  arr[123] = 777744;
  arr[124] = 777747;
  arr[125] = 777774;
  arr[126] = 777777;
  arr[127] = 4444444;
  arr[128] = 4444447;
  arr[129] = 4444474;
  arr[130] = 4444477;
  arr[131] = 4444744;
  arr[132] = 4444747;
  arr[133] = 4444774;
  arr[134] = 4444777;
  arr[135] = 4447444;
  arr[136] = 4447447;
  arr[137] = 4447474;
  arr[138] = 4447477;
  arr[139] = 4447744;
  arr[140] = 4447747;
  arr[141] = 4447774;
  arr[142] = 4447777;
  arr[143] = 4474444;
  arr[144] = 4474447;
  arr[145] = 4474474;
  arr[146] = 4474477;
  arr[147] = 4474744;
  arr[148] = 4474747;
  arr[149] = 4474774;
  arr[150] = 4474777;
  arr[151] = 4477444;
  arr[152] = 4477447;
  arr[153] = 4477474;
  arr[154] = 4477477;
  arr[155] = 4477744;
  arr[156] = 4477747;
  arr[157] = 4477774;
  arr[158] = 4477777;
  arr[159] = 4744444;
  arr[160] = 4744447;
  arr[161] = 4744474;
  arr[162] = 4744477;
  arr[163] = 4744744;
  arr[164] = 4744747;
  arr[165] = 4744774;
  arr[166] = 4744777;
  arr[167] = 4747444;
  arr[168] = 4747447;
  arr[169] = 4747474;
  arr[170] = 4747477;
  arr[171] = 4747744;
  arr[172] = 4747747;
  arr[173] = 4747774;
  arr[174] = 4747777;
  arr[175] = 4774444;
  arr[176] = 4774447;
  arr[177] = 4774474;
  arr[178] = 4774477;
  arr[179] = 4774744;
  arr[180] = 4774747;
  arr[181] = 4774774;
  arr[182] = 4774777;
  arr[183] = 4777444;
  arr[184] = 4777447;
  arr[185] = 4777474;
  arr[186] = 4777477;
  arr[187] = 4777744;
  arr[188] = 4777747;
  arr[189] = 4777774;
  arr[190] = 4777777;
  arr[191] = 7444444;
  arr[192] = 7444447;
  arr[193] = 7444474;
  arr[194] = 7444477;
  arr[195] = 7444744;
  arr[196] = 7444747;
  arr[197] = 7444774;
  arr[198] = 7444777;
  arr[199] = 7447444;
  arr[200] = 7447447;
  arr[201] = 7447474;
  arr[202] = 7447477;
  arr[203] = 7447744;
  arr[204] = 7447747;
  arr[205] = 7447774;
  arr[206] = 7447777;
  arr[207] = 7474444;
  arr[208] = 7474447;
  arr[209] = 7474474;
  arr[210] = 7474477;
  arr[211] = 7474744;
  arr[212] = 7474747;
  arr[213] = 7474774;
  arr[214] = 7474777;
  arr[215] = 7477444;
  arr[216] = 7477447;
  arr[217] = 7477474;
  arr[218] = 7477477;
  arr[219] = 7477744;
  arr[220] = 7477747;
  arr[221] = 7477774;
  arr[222] = 7477777;
  arr[223] = 7744444;
  arr[224] = 7744447;
  arr[225] = 7744474;
  arr[226] = 7744477;
  arr[227] = 7744744;
  arr[228] = 7744747;
  arr[229] = 7744774;
  arr[230] = 7744777;
  arr[231] = 7747444;
  arr[232] = 7747447;
  arr[233] = 7747474;
  arr[234] = 7747477;
  arr[235] = 7747744;
  arr[236] = 7747747;
  arr[237] = 7747774;
  arr[238] = 7747777;
  arr[239] = 7774444;
  arr[240] = 7774447;
  arr[241] = 7774474;
  arr[242] = 7774477;
  arr[243] = 7774744;
  arr[244] = 7774747;
  arr[245] = 7774774;
  arr[246] = 7774777;
  arr[247] = 7777444;
  arr[248] = 7777447;
  arr[249] = 7777474;
  arr[250] = 7777477;
  arr[251] = 7777744;
  arr[252] = 7777747;
  arr[253] = 7777774;
  arr[254] = 7777777;
  arr[255] = 44444444;
  arr[256] = 44444447;
  arr[257] = 44444474;
  arr[258] = 44444477;
  arr[259] = 44444744;
  arr[260] = 44444747;
  arr[261] = 44444774;
  arr[262] = 44444777;
  arr[263] = 44447444;
  arr[264] = 44447447;
  arr[265] = 44447474;
  arr[266] = 44447477;
  arr[267] = 44447744;
  arr[268] = 44447747;
  arr[269] = 44447774;
  arr[270] = 44447777;
  arr[271] = 44474444;
  arr[272] = 44474447;
  arr[273] = 44474474;
  arr[274] = 44474477;
  arr[275] = 44474744;
  arr[276] = 44474747;
  arr[277] = 44474774;
  arr[278] = 44474777;
  arr[279] = 44477444;
  arr[280] = 44477447;
  arr[281] = 44477474;
  arr[282] = 44477477;
  arr[283] = 44477744;
  arr[284] = 44477747;
  arr[285] = 44477774;
  arr[286] = 44477777;
  arr[287] = 44744444;
  arr[288] = 44744447;
  arr[289] = 44744474;
  arr[290] = 44744477;
  arr[291] = 44744744;
  arr[292] = 44744747;
  arr[293] = 44744774;
  arr[294] = 44744777;
  arr[295] = 44747444;
  arr[296] = 44747447;
  arr[297] = 44747474;
  arr[298] = 44747477;
  arr[299] = 44747744;
  arr[300] = 44747747;
  arr[301] = 44747774;
  arr[302] = 44747777;
  arr[303] = 44774444;
  arr[304] = 44774447;
  arr[305] = 44774474;
  arr[306] = 44774477;
  arr[307] = 44774744;
  arr[308] = 44774747;
  arr[309] = 44774774;
  arr[310] = 44774777;
  arr[311] = 44777444;
  arr[312] = 44777447;
  arr[313] = 44777474;
  arr[314] = 44777477;
  arr[315] = 44777744;
  arr[316] = 44777747;
  arr[317] = 44777774;
  arr[318] = 44777777;
  arr[319] = 47444444;
  arr[320] = 47444447;
  arr[321] = 47444474;
  arr[322] = 47444477;
  arr[323] = 47444744;
  arr[324] = 47444747;
  arr[325] = 47444774;
  arr[326] = 47444777;
  arr[327] = 47447444;
  arr[328] = 47447447;
  arr[329] = 47447474;
  arr[330] = 47447477;
  arr[331] = 47447744;
  arr[332] = 47447747;
  arr[333] = 47447774;
  arr[334] = 47447777;
  arr[335] = 47474444;
  arr[336] = 47474447;
  arr[337] = 47474474;
  arr[338] = 47474477;
  arr[339] = 47474744;
  arr[340] = 47474747;
  arr[341] = 47474774;
  arr[342] = 47474777;
  arr[343] = 47477444;
  arr[344] = 47477447;
  arr[345] = 47477474;
  arr[346] = 47477477;
  arr[347] = 47477744;
  arr[348] = 47477747;
  arr[349] = 47477774;
  arr[350] = 47477777;
  arr[351] = 47744444;
  arr[352] = 47744447;
  arr[353] = 47744474;
  arr[354] = 47744477;
  arr[355] = 47744744;
  arr[356] = 47744747;
  arr[357] = 47744774;
  arr[358] = 47744777;
  arr[359] = 47747444;
  arr[360] = 47747447;
  arr[361] = 47747474;
  arr[362] = 47747477;
  arr[363] = 47747744;
  arr[364] = 47747747;
  arr[365] = 47747774;
  arr[366] = 47747777;
  arr[367] = 47774444;
  arr[368] = 47774447;
  arr[369] = 47774474;
  arr[370] = 47774477;
  arr[371] = 47774744;
  arr[372] = 47774747;
  arr[373] = 47774774;
  arr[374] = 47774777;
  arr[375] = 47777444;
  arr[376] = 47777447;
  arr[377] = 47777474;
  arr[378] = 47777477;
  arr[379] = 47777744;
  arr[380] = 47777747;
  arr[381] = 47777774;
  arr[382] = 47777777;
  arr[383] = 74444444;
  arr[384] = 74444447;
  arr[385] = 74444474;
  arr[386] = 74444477;
  arr[387] = 74444744;
  arr[388] = 74444747;
  arr[389] = 74444774;
  arr[390] = 74444777;
  arr[391] = 74447444;
  arr[392] = 74447447;
  arr[393] = 74447474;
  arr[394] = 74447477;
  arr[395] = 74447744;
  arr[396] = 74447747;
  arr[397] = 74447774;
  arr[398] = 74447777;
  arr[399] = 74474444;
  arr[400] = 74474447;
  arr[401] = 74474474;
  arr[402] = 74474477;
  arr[403] = 74474744;
  arr[404] = 74474747;
  arr[405] = 74474774;
  arr[406] = 74474777;
  arr[407] = 74477444;
  arr[408] = 74477447;
  arr[409] = 74477474;
  arr[410] = 74477477;
  arr[411] = 74477744;
  arr[412] = 74477747;
  arr[413] = 74477774;
  arr[414] = 74477777;
  arr[415] = 74744444;
  arr[416] = 74744447;
  arr[417] = 74744474;
  arr[418] = 74744477;
  arr[419] = 74744744;
  arr[420] = 74744747;
  arr[421] = 74744774;
  arr[422] = 74744777;
  arr[423] = 74747444;
  arr[424] = 74747447;
  arr[425] = 74747474;
  arr[426] = 74747477;
  arr[427] = 74747744;
  arr[428] = 74747747;
  arr[429] = 74747774;
  arr[430] = 74747777;
  arr[431] = 74774444;
  arr[432] = 74774447;
  arr[433] = 74774474;
  arr[434] = 74774477;
  arr[435] = 74774744;
  arr[436] = 74774747;
  arr[437] = 74774774;
  arr[438] = 74774777;
  arr[439] = 74777444;
  arr[440] = 74777447;
  arr[441] = 74777474;
  arr[442] = 74777477;
  arr[443] = 74777744;
  arr[444] = 74777747;
  arr[445] = 74777774;
  arr[446] = 74777777;
  arr[447] = 77444444;
  arr[448] = 77444447;
  arr[449] = 77444474;
  arr[450] = 77444477;
  arr[451] = 77444744;
  arr[452] = 77444747;
  arr[453] = 77444774;
  arr[454] = 77444777;
  arr[455] = 77447444;
  arr[456] = 77447447;
  arr[457] = 77447474;
  arr[458] = 77447477;
  arr[459] = 77447744;
  arr[460] = 77447747;
  arr[461] = 77447774;
  arr[462] = 77447777;
  arr[463] = 77474444;
  arr[464] = 77474447;
  arr[465] = 77474474;
  arr[466] = 77474477;
  arr[467] = 77474744;
  arr[468] = 77474747;
  arr[469] = 77474774;
  arr[470] = 77474777;
  arr[471] = 77477444;
  arr[472] = 77477447;
  arr[473] = 77477474;
  arr[474] = 77477477;
  arr[475] = 77477744;
  arr[476] = 77477747;
  arr[477] = 77477774;
  arr[478] = 77477777;
  arr[479] = 77744444;
  arr[480] = 77744447;
  arr[481] = 77744474;
  arr[482] = 77744477;
  arr[483] = 77744744;
  arr[484] = 77744747;
  arr[485] = 77744774;
  arr[486] = 77744777;
  arr[487] = 77747444;
  arr[488] = 77747447;
  arr[489] = 77747474;
  arr[490] = 77747477;
  arr[491] = 77747744;
  arr[492] = 77747747;
  arr[493] = 77747774;
  arr[494] = 77747777;
  arr[495] = 77774444;
  arr[496] = 77774447;
  arr[497] = 77774474;
  arr[498] = 77774477;
  arr[499] = 77774744;
  arr[500] = 77774747;
  arr[501] = 77774774;
  arr[502] = 77774777;
  arr[503] = 77777444;
  arr[504] = 77777447;
  arr[505] = 77777474;
  arr[506] = 77777477;
  arr[507] = 77777744;
  arr[508] = 77777747;
  arr[509] = 77777774;
  arr[510] = 77777777;
  arr[511] = 444444444;
  arr[512] = 444444447;
  arr[513] = 444444474;
  arr[514] = 444444477;
  arr[515] = 444444744;
  arr[516] = 444444747;
  arr[517] = 444444774;
  arr[518] = 444444777;
  arr[519] = 444447444;
  arr[520] = 444447447;
  arr[521] = 444447474;
  arr[522] = 444447477;
  arr[523] = 444447744;
  arr[524] = 444447747;
  arr[525] = 444447774;
  arr[526] = 444447777;
  arr[527] = 444474444;
  arr[528] = 444474447;
  arr[529] = 444474474;
  arr[530] = 444474477;
  arr[531] = 444474744;
  arr[532] = 444474747;
  arr[533] = 444474774;
  arr[534] = 444474777;
  arr[535] = 444477444;
  arr[536] = 444477447;
  arr[537] = 444477474;
  arr[538] = 444477477;
  arr[539] = 444477744;
  arr[540] = 444477747;
  arr[541] = 444477774;
  arr[542] = 444477777;
  arr[543] = 444744444;
  arr[544] = 444744447;
  arr[545] = 444744474;
  arr[546] = 444744477;
  arr[547] = 444744744;
  arr[548] = 444744747;
  arr[549] = 444744774;
  arr[550] = 444744777;
  arr[551] = 444747444;
  arr[552] = 444747447;
  arr[553] = 444747474;
  arr[554] = 444747477;
  arr[555] = 444747744;
  arr[556] = 444747747;
  arr[557] = 444747774;
  arr[558] = 444747777;
  arr[559] = 444774444;
  arr[560] = 444774447;
  arr[561] = 444774474;
  arr[562] = 444774477;
  arr[563] = 444774744;
  arr[564] = 444774747;
  arr[565] = 444774774;
  arr[566] = 444774777;
  arr[567] = 444777444;
  arr[568] = 444777447;
  arr[569] = 444777474;
  arr[570] = 444777477;
  arr[571] = 444777744;
  arr[572] = 444777747;
  arr[573] = 444777774;
  arr[574] = 444777777;
  arr[575] = 447444444;
  arr[576] = 447444447;
  arr[577] = 447444474;
  arr[578] = 447444477;
  arr[579] = 447444744;
  arr[580] = 447444747;
  arr[581] = 447444774;
  arr[582] = 447444777;
  arr[583] = 447447444;
  arr[584] = 447447447;
  arr[585] = 447447474;
  arr[586] = 447447477;
  arr[587] = 447447744;
  arr[588] = 447447747;
  arr[589] = 447447774;
  arr[590] = 447447777;
  arr[591] = 447474444;
  arr[592] = 447474447;
  arr[593] = 447474474;
  arr[594] = 447474477;
  arr[595] = 447474744;
  arr[596] = 447474747;
  arr[597] = 447474774;
  arr[598] = 447474777;
  arr[599] = 447477444;
  arr[600] = 447477447;
  arr[601] = 447477474;
  arr[602] = 447477477;
  arr[603] = 447477744;
  arr[604] = 447477747;
  arr[605] = 447477774;
  arr[606] = 447477777;
  arr[607] = 447744444;
  arr[608] = 447744447;
  arr[609] = 447744474;
  arr[610] = 447744477;
  arr[611] = 447744744;
  arr[612] = 447744747;
  arr[613] = 447744774;
  arr[614] = 447744777;
  arr[615] = 447747444;
  arr[616] = 447747447;
  arr[617] = 447747474;
  arr[618] = 447747477;
  arr[619] = 447747744;
  arr[620] = 447747747;
  arr[621] = 447747774;
  arr[622] = 447747777;
  arr[623] = 447774444;
  arr[624] = 447774447;
  arr[625] = 447774474;
  arr[626] = 447774477;
  arr[627] = 447774744;
  arr[628] = 447774747;
  arr[629] = 447774774;
  arr[630] = 447774777;
  arr[631] = 447777444;
  arr[632] = 447777447;
  arr[633] = 447777474;
  arr[634] = 447777477;
  arr[635] = 447777744;
  arr[636] = 447777747;
  arr[637] = 447777774;
  arr[638] = 447777777;
  arr[639] = 474444444;
  arr[640] = 474444447;
  arr[641] = 474444474;
  arr[642] = 474444477;
  arr[643] = 474444744;
  arr[644] = 474444747;
  arr[645] = 474444774;
  arr[646] = 474444777;
  arr[647] = 474447444;
  arr[648] = 474447447;
  arr[649] = 474447474;
  arr[650] = 474447477;
  arr[651] = 474447744;
  arr[652] = 474447747;
  arr[653] = 474447774;
  arr[654] = 474447777;
  arr[655] = 474474444;
  arr[656] = 474474447;
  arr[657] = 474474474;
  arr[658] = 474474477;
  arr[659] = 474474744;
  arr[660] = 474474747;
  arr[661] = 474474774;
  arr[662] = 474474777;
  arr[663] = 474477444;
  arr[664] = 474477447;
  arr[665] = 474477474;
  arr[666] = 474477477;
  arr[667] = 474477744;
  arr[668] = 474477747;
  arr[669] = 474477774;
  arr[670] = 474477777;
  arr[671] = 474744444;
  arr[672] = 474744447;
  arr[673] = 474744474;
  arr[674] = 474744477;
  arr[675] = 474744744;
  arr[676] = 474744747;
  arr[677] = 474744774;
  arr[678] = 474744777;
  arr[679] = 474747444;
  arr[680] = 474747447;
  arr[681] = 474747474;
  arr[682] = 474747477;
  arr[683] = 474747744;
  arr[684] = 474747747;
  arr[685] = 474747774;
  arr[686] = 474747777;
  arr[687] = 474774444;
  arr[688] = 474774447;
  arr[689] = 474774474;
  arr[690] = 474774477;
  arr[691] = 474774744;
  arr[692] = 474774747;
  arr[693] = 474774774;
  arr[694] = 474774777;
  arr[695] = 474777444;
  arr[696] = 474777447;
  arr[697] = 474777474;
  arr[698] = 474777477;
  arr[699] = 474777744;
  arr[700] = 474777747;
  arr[701] = 474777774;
  arr[702] = 474777777;
  arr[703] = 477444444;
  arr[704] = 477444447;
  arr[705] = 477444474;
  arr[706] = 477444477;
  arr[707] = 477444744;
  arr[708] = 477444747;
  arr[709] = 477444774;
  arr[710] = 477444777;
  arr[711] = 477447444;
  arr[712] = 477447447;
  arr[713] = 477447474;
  arr[714] = 477447477;
  arr[715] = 477447744;
  arr[716] = 477447747;
  arr[717] = 477447774;
  arr[718] = 477447777;
  arr[719] = 477474444;
  arr[720] = 477474447;
  arr[721] = 477474474;
  arr[722] = 477474477;
  arr[723] = 477474744;
  arr[724] = 477474747;
  arr[725] = 477474774;
  arr[726] = 477474777;
  arr[727] = 477477444;
  arr[728] = 477477447;
  arr[729] = 477477474;
  arr[730] = 477477477;
  arr[731] = 477477744;
  arr[732] = 477477747;
  arr[733] = 477477774;
  arr[734] = 477477777;
  arr[735] = 477744444;
  arr[736] = 477744447;
  arr[737] = 477744474;
  arr[738] = 477744477;
  arr[739] = 477744744;
  arr[740] = 477744747;
  arr[741] = 477744774;
  arr[742] = 477744777;
  arr[743] = 477747444;
  arr[744] = 477747447;
  arr[745] = 477747474;
  arr[746] = 477747477;
  arr[747] = 477747744;
  arr[748] = 477747747;
  arr[749] = 477747774;
  arr[750] = 477747777;
  arr[751] = 477774444;
  arr[752] = 477774447;
  arr[753] = 477774474;
  arr[754] = 477774477;
  arr[755] = 477774744;
  arr[756] = 477774747;
  arr[757] = 477774774;
  arr[758] = 477774777;
  arr[759] = 477777444;
  arr[760] = 477777447;
  arr[761] = 477777474;
  arr[762] = 477777477;
  arr[763] = 477777744;
  arr[764] = 477777747;
  arr[765] = 477777774;
  arr[766] = 477777777;
  arr[767] = 744444444;
  arr[768] = 744444447;
  arr[769] = 744444474;
  arr[770] = 744444477;
  arr[771] = 744444744;
  arr[772] = 744444747;
  arr[773] = 744444774;
  arr[774] = 744444777;
  arr[775] = 744447444;
  arr[776] = 744447447;
  arr[777] = 744447474;
  arr[778] = 744447477;
  arr[779] = 744447744;
  arr[780] = 744447747;
  arr[781] = 744447774;
  arr[782] = 744447777;
  arr[783] = 744474444;
  arr[784] = 744474447;
  arr[785] = 744474474;
  arr[786] = 744474477;
  arr[787] = 744474744;
  arr[788] = 744474747;
  arr[789] = 744474774;
  arr[790] = 744474777;
  arr[791] = 744477444;
  arr[792] = 744477447;
  arr[793] = 744477474;
  arr[794] = 744477477;
  arr[795] = 744477744;
  arr[796] = 744477747;
  arr[797] = 744477774;
  arr[798] = 744477777;
  arr[799] = 744744444;
  arr[800] = 744744447;
  arr[801] = 744744474;
  arr[802] = 744744477;
  arr[803] = 744744744;
  arr[804] = 744744747;
  arr[805] = 744744774;
  arr[806] = 744744777;
  arr[807] = 744747444;
  arr[808] = 744747447;
  arr[809] = 744747474;
  arr[810] = 744747477;
  arr[811] = 744747744;
  arr[812] = 744747747;
  arr[813] = 744747774;
  arr[814] = 744747777;
  arr[815] = 744774444;
  arr[816] = 744774447;
  arr[817] = 744774474;
  arr[818] = 744774477;
  arr[819] = 744774744;
  arr[820] = 744774747;
  arr[821] = 744774774;
  arr[822] = 744774777;
  arr[823] = 744777444;
  arr[824] = 744777447;
  arr[825] = 744777474;
  arr[826] = 744777477;
  arr[827] = 744777744;
  arr[828] = 744777747;
  arr[829] = 744777774;
  arr[830] = 744777777;
  arr[831] = 747444444;
  arr[832] = 747444447;
  arr[833] = 747444474;
  arr[834] = 747444477;
  arr[835] = 747444744;
  arr[836] = 747444747;
  arr[837] = 747444774;
  arr[838] = 747444777;
  arr[839] = 747447444;
  arr[840] = 747447447;
  arr[841] = 747447474;
  arr[842] = 747447477;
  arr[843] = 747447744;
  arr[844] = 747447747;
  arr[845] = 747447774;
  arr[846] = 747447777;
  arr[847] = 747474444;
  arr[848] = 747474447;
  arr[849] = 747474474;
  arr[850] = 747474477;
  arr[851] = 747474744;
  arr[852] = 747474747;
  arr[853] = 747474774;
  arr[854] = 747474777;
  arr[855] = 747477444;
  arr[856] = 747477447;
  arr[857] = 747477474;
  arr[858] = 747477477;
  arr[859] = 747477744;
  arr[860] = 747477747;
  arr[861] = 747477774;
  arr[862] = 747477777;
  arr[863] = 747744444;
  arr[864] = 747744447;
  arr[865] = 747744474;
  arr[866] = 747744477;
  arr[867] = 747744744;
  arr[868] = 747744747;
  arr[869] = 747744774;
  arr[870] = 747744777;
  arr[871] = 747747444;
  arr[872] = 747747447;
  arr[873] = 747747474;
  arr[874] = 747747477;
  arr[875] = 747747744;
  arr[876] = 747747747;
  arr[877] = 747747774;
  arr[878] = 747747777;
  arr[879] = 747774444;
  arr[880] = 747774447;
  arr[881] = 747774474;
  arr[882] = 747774477;
  arr[883] = 747774744;
  arr[884] = 747774747;
  arr[885] = 747774774;
  arr[886] = 747774777;
  arr[887] = 747777444;
  arr[888] = 747777447;
  arr[889] = 747777474;
  arr[890] = 747777477;
  arr[891] = 747777744;
  arr[892] = 747777747;
  arr[893] = 747777774;
  arr[894] = 747777777;
  arr[895] = 774444444;
  arr[896] = 774444447;
  arr[897] = 774444474;
  arr[898] = 774444477;
  arr[899] = 774444744;
  arr[900] = 774444747;
  arr[901] = 774444774;
  arr[902] = 774444777;
  arr[903] = 774447444;
  arr[904] = 774447447;
  arr[905] = 774447474;
  arr[906] = 774447477;
  arr[907] = 774447744;
  arr[908] = 774447747;
  arr[909] = 774447774;
  arr[910] = 774447777;
  arr[911] = 774474444;
  arr[912] = 774474447;
  arr[913] = 774474474;
  arr[914] = 774474477;
  arr[915] = 774474744;
  arr[916] = 774474747;
  arr[917] = 774474774;
  arr[918] = 774474777;
  arr[919] = 774477444;
  arr[920] = 774477447;
  arr[921] = 774477474;
  arr[922] = 774477477;
  arr[923] = 774477744;
  arr[924] = 774477747;
  arr[925] = 774477774;
  arr[926] = 774477777;
  arr[927] = 774744444;
  arr[928] = 774744447;
  arr[929] = 774744474;
  arr[930] = 774744477;
  arr[931] = 774744744;
  arr[932] = 774744747;
  arr[933] = 774744774;
  arr[934] = 774744777;
  arr[935] = 774747444;
  arr[936] = 774747447;
  arr[937] = 774747474;
  arr[938] = 774747477;
  arr[939] = 774747744;
  arr[940] = 774747747;
  arr[941] = 774747774;
  arr[942] = 774747777;
  arr[943] = 774774444;
  arr[944] = 774774447;
  arr[945] = 774774474;
  arr[946] = 774774477;
  arr[947] = 774774744;
  arr[948] = 774774747;
  arr[949] = 774774774;
  arr[950] = 774774777;
  arr[951] = 774777444;
  arr[952] = 774777447;
  arr[953] = 774777474;
  arr[954] = 774777477;
  arr[955] = 774777744;
  arr[956] = 774777747;
  arr[957] = 774777774;
  arr[958] = 774777777;
  arr[959] = 777444444;
  arr[960] = 777444447;
  arr[961] = 777444474;
  arr[962] = 777444477;
  arr[963] = 777444744;
  arr[964] = 777444747;
  arr[965] = 777444774;
  arr[966] = 777444777;
  arr[967] = 777447444;
  arr[968] = 777447447;
  arr[969] = 777447474;
  arr[970] = 777447477;
  arr[971] = 777447744;
  arr[972] = 777447747;
  arr[973] = 777447774;
  arr[974] = 777447777;
  arr[975] = 777474444;
  arr[976] = 777474447;
  arr[977] = 777474474;
  arr[978] = 777474477;
  arr[979] = 777474744;
  arr[980] = 777474747;
  arr[981] = 777474774;
  arr[982] = 777474777;
  arr[983] = 777477444;
  arr[984] = 777477447;
  arr[985] = 777477474;
  arr[986] = 777477477;
  arr[987] = 777477744;
  arr[988] = 777477747;
  arr[989] = 777477774;
  arr[990] = 777477777;
  arr[991] = 777744444;
  arr[992] = 777744447;
  arr[993] = 777744474;
  arr[994] = 777744477;
  arr[995] = 777744744;
  arr[996] = 777744747;
  arr[997] = 777744774;
  arr[998] = 777744777;
  arr[999] = 777747444;
  arr[1000] = 777747447;
  arr[1001] = 777747474;
  arr[1002] = 777747477;
  arr[1003] = 777747744;
  arr[1004] = 777747747;
  arr[1005] = 777747774;
  arr[1006] = 777747777;
  arr[1007] = 777774444;
  arr[1008] = 777774447;
  arr[1009] = 777774474;
  arr[1010] = 777774477;
  arr[1011] = 777774744;
  arr[1012] = 777774747;
  arr[1013] = 777774774;
  arr[1014] = 777774777;
  arr[1015] = 777777444;
  arr[1016] = 777777447;
  arr[1017] = 777777474;
  arr[1018] = 777777477;
  arr[1019] = 777777744;
  arr[1020] = 777777747;
  arr[1021] = 777777774;
  arr[1022] = 777777777;
  long long n;
  cin >> n;
  for (int i = 1; i <= 1022; i++) {
    if (arr[i] == n) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
