#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;

vector<pair<long, long>> Prime_Factorization(long n) {
	vector<pair<long,long>> v;

	if (n == 1) {
		v.push_back(make_pair(1, 1));
		return v;
	}

	long k = 2;
	while (k * k <= n) {
		if (n % k == 0) {
			long c = 0;
			while (n % k == 0) {
				c++;
				n /= k;
			}
			v.push_back(make_pair(k, c));
		}
		k++;
	}

	if (n != 1) {
		v.push_back(make_pair(n, 1));
	}

	return v;
}

long power(long a, long n) {
	long ans = 1;
	long x = a;

	while (n > 0) {
		if (n % 2 == 1) {
			ans *= x;
		}
		x *= x;
		n /= 2;
	}
	return ans;
}

long power_mod(long a, long n, long m) {
	long ans = 1;
	long x = a % m;

	while (n > 0) {
		if (n % 2 == 1) {
			ans = (ans * x) % m;
		}
		x = (x * x) % m;
		n /= 2;
	}
	return ans;
}

long Euler_Totient(long n) {
	if (n == 1) {
		return 1;
	}

	vector<pair<long, long>> p;
	p = Prime_Factorization(n);

	long R = 1;

	for (long i = 0; i < p.size(); i++) {
		R *= power(p.at(i).first, p.at(i).second - 1) * (p.at(i).first - 1);
	}

	return R;
}

vector<long> Divisors(long n) {
	vector<long> u, v;

	long k = 1;

	while (k * k <= n) {
		if (n % k == 0) {
			u.push_back(k);
			if (k != n / k) {
				v.push_back(n / k);
			}
		}
		k++;
	}
	reverse(begin(v), end(v));
	u.insert(u.end(), v.begin(), v.end());
	return u;
}


int main() {
	long a = 1;
	long ans = 0;

	long N;
	cin >> N;

	long phi = Euler_Totient(2 * N - 1);
	vector<long> v = Divisors(phi);
	reverse(begin(v), end(v));


	for (int i = 0; i < v.size(); i++) {
		if ((power_mod(2, v.at(i), 2 * N - 1)-1)%(2*N-1)==0) {
			ans = v.at(i);
		}
	}

	cout << ans << endl;
}