PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000062. Biểu diễn số K-tốt (K-good)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Biểu diễn số K-tốt (K-good)

K-good

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer n is k-good if it is the sum of exactly k positive integers whose remainders modulo k are pairwise distinct. Find any integer k>=2 for which n is k-good; print -1 if no such k exists. Different valid values of k are all accepted.

Input

An integer n.

Output

Any valid k>=2 or -1 if no valid value exists.

Subtasks

  • Subtask 1 (20 points): 2≤n≤10002\le n\le 1000.
  • Subtask 2 (30 points): 2≤n≤1092\le n\le 10^9.
  • Subtask 3 (50 points): 2≤n≤10182\le n\le 10^{18}.

Examples

Input

6

Output

3

Explanation

The representation 6=1+2+3 has three distinct remainders modulo 3.