#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} template void writerLn(T x){writer(x,'\n');} template int extend(const char arr[], T res[]){int i,j,s=1,z=0;static int c[128],f=0;if(f==0)REP(i,33,127)if(i!=34&&i!=92)c[i]=f++;if(arr[0]<' ')return 0;res[0]=0;for(i=0;;i++){if(arr[i]<' ')break;if(c[arr[i]]<46)res[z]=res[z]*46+c[arr[i]];else{res[z]=res[z]*46+c[arr[i]]-46;if(s==-1)res[z]*=-1,s=1;res[++z]=0;}}return z;} const char *buf = "Q?-=.f#0I,3Q$!=0Dv$CJB-_%6*MEQ&*(?)R&M0<6y'@71Iq(4!A#u)(/HCg)KJ@*n*@19?d+6B#+_,.0,B_,O+FHS-C1B%T.7.)7R/,=$Cz/O=?Mt0EG!!{1>(/)~22.E9a3(/&*W3M;,;c4D>;I[5(**-k>MA4Bw?E*/Ib@>&1*bA6?DNpB+5D.xBOAN;SCGG8=XD>3E$lE6>L#~F056%cG'J,=|GMN*HeHG081qI@A1=lJ;$26VK6@B:kL+/2;uLM!F@UMA.-CeN6@25{O+162{OO)'w#'?,F,q#(6H>Mp#),$*#y#*!;AEb#*H5&6s#+?-+2P#,7B3D|#-2-O(V#.(:4=}#.O!BLg#/HN>#p#0AM(7q#1<(&BJl#>NK=DZ#?H<60s#@B/)&w#A=2AE]#B84J+Q#C2/2Cf#D-/F3R#E)*;-c#F%E3Oa#G!O8(q#GGC/;X#H;(-If#I//69z#J%)($i$#,IC0R$$$NO&n$$H&OBb$%>3<(o$&6F'!f$'-$+Ob$(%:@HU$(M8*({$)D7.8~$*&(57w$>M?#!^$?HEE+Q$@D>6,_$A@@OOt$B=NKLY$C77*7}$D,L)4k$E#7OHz$EI)4!V$F@(#Gg$G8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ull a){ return memo[(a>>32)] + memo[(a>>16)%65535U] + memo[a%65535U]; } int main(){ int j, k; ll i, x, N; extend(buf, arr); REP(i,1,1<<16) memo[i] = memo[i&(i-1)]+1; reader(&N); for(i=0;;i++) if(arr[i+1] > N) break; x = arr[i]; i *= 10000000; i++; while(x < N){ i++; x += bitcount(x); } if(x!=N) i = -1; writerLn(i); return 0; }