void main() {
    int x = readln.chomp.to!int;
    bool[] ok = new bool[x+1];
    ok[1] = true;
    for (int i = 2; i * i <= x; ++i) {
        for (int j = 2; i ^^ j <= x; ++j) {
            ok[i^^j] = true;
        }
    }
    foreach_reverse (i, y; ok) {
        if (y) {
            i.writeln;
            break;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;