var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var n = N
    var ans = N - 1;

    while (n % 2 === 0) {
        if (n / 2 === 2) { break; }
        n = n / 2;

        if (N % (n - 1) === 0) { break; }
        ans += n - 1;
        
    }

    console.log(ans);
});