文件目录

#include <bits/stdc++.h>
using namespace std;
int main()
{
    queue<int> q;
    int n, x[1000050] = {};
    cin >> n;
    for (int i = 1; i <= n; i++)
        q.push(i);
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    int i = 1;
    int m = x[1];
    while (q.size() != 1)
    {
        if (i != m)
        {
            q.push(q.front());
            q.pop();
            i++;
        }
        else
        {
            // cout<<q.front()<<" ";
            q.pop();
            i = 1;
            m = x[q.front()];
        }
    }
    cout << q.front();
    return 0;
}