n,a,b,c;main(){for(;a=scanf("%d",&n),n;){for(;!(a&n);a*=2);for(b=a;a&n;n^=a,a*=2);for(n|=a,c=1;!(a&b*2);b*=2,c*=2)n|=c;printf("%d\n",n);}}