#import <ios>
inline long long redn() {
long long ret=0; char ch=getchar_unlocked();
if(ch == EOF) return -1;
while (ch>='0'&&ch<='9') ret=ret*10+ch-'0', ch=getchar_unlocked();
return ret;
}
inline void wrtn(long long x) {
long long y=10, len=1;
if (x<0) putchar_unlocked('-'), x=~x+1;
while(y<=x) y*=10, len++;
while(len--) y/=10, putchar_unlocked(x/y+48), x%=y;
putchar_unlocked(10);
}
long long down_2(long long x) {
long down=1;
while (down<=x) {
down<<=1;
}
return down>>1;
}
int main() {
long long a;
for (;(a=redn())!=-1;) {
long long ans, down;
down=down_2(a), ans=down>>1;
if (down==a) wrtn(a);
else {
while (down+ans<a) {
down+=ans, ans>>=1;
if (down+1==a) break;
}
wrtn(ans);
}
}
return 0;
}