ll@Q,@Y,A[Q],L;VS@S(Q);auto f=[&](ll x){L=0;for(auto&s:S)"0">s?A[L-2]+=A[L-1],--L:"m">s?A[L++]="X">s?stoi(s):x:"mi">s?(A[L-2]>?=A[L-1]),--L:(A[L-2]=Y))==Y?Q:-1);