#include <iostream>
using namespace std;
int main() {
int n, v[900000], m, w[400000], x;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
for (int j = 1; j <= m; ++j) {
cin >> w[j];
if (w[j] == 1) {
for (int i = 1; i < n; ++i) {
v[i] = v[i + 1];
}
--n;
}
if (w[j] == 2) {
++n;
cin >> x;
v[n] = x;
}
}
cout << n << "\n ";
for (int i = 1; i <= n; ++i) {
cout << v[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgdls5MDAwMDBdLCBtLCB3WzQwMDAwMF0sIHg7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV07CiAgICB9CiAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opIHsKICAgICAgICBjaW4gPj4gd1tqXTsKICAgICAgICBpZiAod1tqXSA9PSAxKSB7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICAgICAgICB2W2ldID0gdltpICsgMV07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLS1uOwogICAgICAgIH0KICAgICAgICBpZiAod1tqXSA9PSAyKSB7CiAgICAgICAgICAgICsrbjsKICAgICAgICAgICAgY2luID4+IHg7CiAgICAgICAgICAgIHZbbl0gPSB4OwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgbiA8PCAiXG4gIjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGNvdXQgPDwgdltpXSA8PCAiICI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==