#import <Foundation/Foundation.h>
@interface Solution: NSObject
+ (NSInteger)leastAttackCountWithN: (NSInteger)N;
@end
@implementation Solution
+ (NSInteger)leastAttackCountWithN: (NSInteger)N {
  if(N==1) {
    return 1;
  }
  return [self leastAttackCountWithN: N / 2] * 2 + 1;
}
@end
int main(int argc, char **argv) {
  	NSInteger v;
	scanf("%ld", &v);
  	printf("%ld", [Solution leastAttackCountWithN: v]);
  	return 0;
}