#include #include #include #include using namespace std; using namespace atcoder; using namespace __gnu_pbds; using ll=long long; using ld=long double; using vll=vector; using vvll=vector; using pll=pair; // using mint=modint; // template // using ordered_map=tree,rb_tree_tag,tree_order_statistics_node_update>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //エスパーなんですけど //m を m+1,m+2,...,N がaの中にすでにその順で並んでいるのような最小のmとして、最適解はmです ll N; cin>>N; vll pos(N+1); for(int i=1,a;i<=N;++i)cin>>a,pos[a]=i; for(int i=N;i>=2;--i){ if(pos[i-1]>pos[i]){ cout<