//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = ::std::int_least8_t;
	using i32 = ::std::int_least32_t;
	using i64 = ::std::int_least64_t;
	using u8 = ::std::uint_least8_t;
	using u32 = ::std::uint_least32_t;
	using u64 = ::std::uint_least64_t;
	using isize = ::std::ptrdiff_t;
	using usize = ::std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(l - 1); }
		constexpr itr end() const noexcept { return itr(f - 1); }
	};
	template <class T> bool amax(T &a, const T &b) {
		return b < a ? false : (a = b, true);
	}
	template <class T> bool amin(T &a, const T &b) {
		return a < b ? false : (a = b, true);
	}
	template <class T> bool asmax(T &a, const T &b) {
		return a < b ? (a = b, true) : false;
	}
	template <class T> bool asmin(T &a, const T &b) {
		return b < a ? (a = b, true) : false;
	}
	template <class T> using vec_alias = ::std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return ::std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> const T &as_const(const T &v) noexcept { return v; }
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <unordered_map>

namespace n91 {

	template <class T> T gcd(T m, T n) {
		while (m %= n)
			::std::swap(m, n);
		return n;
	}

	u64 lcm(const std::vector<u64> &a) {
		u64 ret = 1;
		for (const auto e : a) {
			ret = ret / gcd(ret, e)*e;
		}
		return ret;
	}

	u64 modpow(u64 a, u64 k, const u64 mod) {
		u64 ret = 1;
		while (k) {
			if (k % 2 == 1) {
				ret = ret*a%mod;
			}
			k /= 2;
			a = a*a%mod;
		}
		return ret;
	}

	u64 dl(u64 a,const u64 mod,const u64 t) {
		u64 i = 1;
		for (;i*i <= mod;++i) {
			if (t % i == 0) {
				if (modpow(a, i, mod) == 1) {
					return i;
				}
			}
		}
		for (;i != 0;--i) {
			if (t % 1 == 0) {
				if (modpow(a, t / i, mod) == 1) {
					return t / i;
				}
			}
		}
	}


	void main_() {
		u64 n;
		std::cin >> n;
		if (n == 2) {
			std::cout << 1 << std::endl;
			return;
		}
		u64 l;
		{
			std::vector<u64> facts;
			u64 c = n;
			for (u64 i = 2;i*i <= c;++i) {
				if (c%i == 0) {
					c /= i;
					if (c%i == 0) {
						std::cout << "-1" << std::endl;
						return;
					}
					facts.emplace_back(i - 1);
				}
			}
			if (c != 1) {
				facts.emplace_back(c - 1);
			}
			l = lcm(facts);
		}
		if (gcd(n, l) != 1) {
			std::cout << "-1" << std::endl;
			return;
		}
		u64 lc = l, t = l;
		for (u64 i = 2;i*i <= lc;++i) {
			if (lc%i == 0) {
				t = t / i*(i - 1);
				while (lc%i == 0) {
					lc /= i;
				}
			}
		}
		if (lc != 1) {
			t = t / lc*(lc - 1);
		}
		u64 i = 1;
		for (;i*i <= t;++i) {
			if (t%i == 0&& modpow(n, i, l) == 1) {
				std::cout << i << std::endl;
				return;
			}
		}
		for (;i != 0;--i) {
			if (t%i == 0 && modpow(n, t/i, l) == 1) {
				std::cout << t/i << std::endl;
				return;
			}
		}
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}



Measured memory_bytes: 3148