main(a,b,c){while(scanf("%d",&a)&&a){for(b=0;!(a&1<<b);++b);for(c=1<<b;a&c;c<<=1);printf("%u\n",(a|c)&~(c-1)|(c>>b+1)-1);}}