#include <iostream>
#define ll long long
using namespace std;
ll n, i, db=0;
bool construct(ll a, bool ok)
{
ll nrb=0;
while (a > 0)
{
if (a % 2 == 1) nrb++;
a = a / 2;
}
if (ok) db = nrb;
else if (nrb == db) return true;
else return false;
}
int main()
{
// ios::sync_with_stdio(false);
cin >> n;
construct(n, true);
//cout << db;
if(db == 1)
{
cout << n / 2 << "\n" << n * 2;
return 0;
}
i = n - 1;
while (i>=1)
{
if (construct(i, false))
{
cout << i;
break;
}
--i;
}
if (i == 0) cout << "-1";
cout << "\n";
i = n + 1;
bool ok = false;
while (!ok)
{
ok = construct(i, false);
if (ok)
{
cout << i;
return 0;
}
++i;
}
cout << "-1";
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file