import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto X = readln.chomp.to!(long);

    long res = 0;
    foreach (b; 1..X+1) {
        foreach (p; 2..10) {
            if (b^^p <= X) {
                res = max(res, b^^p);
            }
        }
    }
    writeln(res);
}
