import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!long; if (N <= 1) { writeln(0); return; } long ans = 1; for (long i = 0; i <= bsr(N); ++i) { if (N & (1 << i)) ans *= 2; } writeln(N - ans + 1); }