#include #include #include #include #include using namespace std; int main() { int n; unsigned int t; cin >> n; vector sg(n+1); vector v(n+1, false); sg[0] = -1; for (int i=1; i q; int u, ub, uf, cnt; q.push(1); u = 1; cnt = 1; while (!q.empty()) { u = q.front(); q.pop(); v[u] = true; ub = u - sg[u]; uf = u + sg[u]; if (!(ub<1) && v[ub]==false) {q.push(ub);cnt++;} if (v[uf]==false && uf<=n) {q.push(uf);cnt++;} } if (u!=n) {cout << -1 << endl;} else {cout << cnt << endl;} return 0; }