#include #include #include #include #include using namespace std; const int DONE = 20000; const int YET = 0; int main() { int n; unsigned int t; vector> sg; cin >> n; sg.resize(n); for (int i=0; i q; int i, u, m, cnt; q.push(0); u = 0; i = 0; m = 0; cnt = 0; while (!q.empty()) { u = q.front(); q.pop(); sg[u].second = DONE; cnt++; m = sg[u].first; if (m%2==0) { for (i=u; i<=u+m; i+=2) { if (i<0 || i>=sg.size()) continue; if (sg[i].second==DONE) continue; q.push(i); } }else { for (i=u+1; i<=u+m; i+=2) { if (i<0 || i>=sg.size()) continue; if (sg[i].second==DONE) continue; q.push(i); } } } if (u != sg.size()-1) {cout << -1 << endl; }else {cout << cnt << endl;} return 0; }