#include <iostream>
using namespace std;
const int MAX_SIZE = 1300000;
int main() {
int n, m, documentsList[MAX_SIZE + 1];
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> documentsList[i];
}
int start = 1;
for (int i = 1; i <= m; ++i) {
int operation;
cin >> operation;
if (operation == 2) {
cin >> documentsList[++n];
} else if (operation == 1 && start <= n) {
++start;
}
}
cout << n - start + 1 << "\n";
for (int i = start; i <= n; ++i) {
cout << documentsList[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTMwMDAwMDsKCmludCBtYWluKCkgewoJaW50IG4sIG0sIGRvY3VtZW50c0xpc3RbTUFYX1NJWkUgKyAxXTsKCWNpbiA+PiBuID4+IG07Cglmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKCQljaW4gPj4gZG9jdW1lbnRzTGlzdFtpXTsKCX0KCWludCBzdGFydCA9IDE7Cglmb3IgKGludCBpID0gMTsgaSA8PSBtOyArK2kpIHsKCQlpbnQgb3BlcmF0aW9uOwoJCWNpbiA+PiBvcGVyYXRpb247CgkJaWYgKG9wZXJhdGlvbiA9PSAyKSB7CgkJCWNpbiA+PiBkb2N1bWVudHNMaXN0Wysrbl07CgkJfSBlbHNlIGlmIChvcGVyYXRpb24gPT0gMSAmJiBzdGFydCA8PSBuKSB7CgkJCSsrc3RhcnQ7CgkJfQoJfQoJY291dCA8PCBuIC0gc3RhcnQgKyAxIDw8ICJcbiI7Cglmb3IgKGludCBpID0gc3RhcnQ7IGkgPD0gbjsgKytpKSB7CgkJY291dCA8PCBkb2N1bWVudHNMaXN0W2ldIDw8ICIgIjsKCX0KCXJldHVybiAwOwp9