#include <iostream>
using namespace std;
int main() {
int n, v[900001], m, w[400001], 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 && n != 0) {
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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgdls5MDAwMDFdLCBtLCB3WzQwMDAwMV0sIHg7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV07CiAgICB9CiAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opIHsKICAgICAgICBjaW4gPj4gd1tqXTsKICAgICAgICBpZiAod1tqXSA9PSAxICYmIG4gIT0gMCkgewogICAgICAgIAlmb3IgKGludCBpID0gMTsgaSA8IG47ICsraSkgewogICAgICAgICAgICAJdltpXSA9IHZbaSArIDFdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIC0tbjsKICAgICAgICB9CiAgICAgICAgaWYgKHdbal0gPT0gMikgewogICAgICAgICAgICArK247CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICB2W25dID0geDsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IG4gPDwgIlxuICI7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBjb3V0IDw8IHZbaV0gPDwgIiAiOwogICAgfQogICAgcmV0dXJuIDA7Cn0=