#include #include #include #include #include #include using namespace std; int a[300000], b[300000], res[300000], t[300000]; typedef pair PI; int main() { int n, m; int ma=(1LL<<31)-1; while (scanf("%d %d", &n, &m) == 2) { if (!n && !m) break; for (int i=0; i x; vector z; x.insert(PI(ma, n)); for (int i=n-1; i>=0; i--) { set::iterator y = x.lower_bound(PI(a[i], i)); b[i] = y->second; x.insert(PI(a[i], i)); z.push_back(PI(a[i], i)); res[i] = -1; } for (int i=0; i= n) break; int u=z[co].second; t[k] = 0; while (u q; for (int i=0; i