import std; void main(){ auto n=readln.chomp.to!(long); long j=cast(long)log2(n); long m=n; for(;j>0;j--){ long i=cast(long)(n^^(1.0/j)); long k=n-(i^^j); stderr.writefln("%d %d %d",i,j,k); m=min(i+j+k,m); } writeln(m); }