#include <bits/stdc++.h>
using namespace std;
#define task "SHT"
bool p(long long a)
{
	long long d=0;
	for (long long i=1;i<a;i++)
	{
		if (a%i==0)
		{
			d=d+i;
		}
	}
	if (a==d)
	{
		return true;
	}
	return false;
}
int main ()
{
	freopen(task".inp","r",stdin);
	freopen(task".out","w",stdout);
	long long a,d=0;
	cin>>a;
	for (long long i=a;i>0;i--)
	{
		if (p(i)==true)
		{
			cout<<i;
			break;
		}
	}
}
