#include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VI a(q), b(q); rep(i, q) cin >> a[i], a[i]--; rep(i, q) cin >> b[i], b[i]--; VVI from(n); int l = 0, r = n - 1; vector> history(n); rep(i, q) { if (a[i] > b[i]) swap(a[i], b[i]); if (a[i] == b[i]) b[i] = n + 5; // cout << i << ' ' << a[i] << ' ' << b[i] << endl; if (l == r) { if (l == a[i] || l == b[i]) { cout << "NO" << '\n'; return 0; } if (0 <= l - 1) { l--; history[l].emplace_back(i, l + 1); } if (r + 1 < n) { r++; history[r].emplace_back(i, r - 1); } } else if (l + 1 == r) { if (l == a[i] || l == b[i]) l++; if (r == a[i] || r == b[i]) r--; if (!(l <= r)) { cout << "NO" << '\n'; return 0; } if (0 <= l - 1) { l--; history[l].emplace_back(i, l + 1); } if (r + 1 < n) { r++; history[r].emplace_back(i, r - 1); } } else if (a[i] + 1 == b[i]) { //cout << "!!" < i) history[now].pop_back(); if (!history[now].empty() && history[now].back().first == i) { int nxt = history[now].back().second; history[now].pop_back(); now = nxt; } ans[i] = now; } cout << ans[0] + 1 << '\n'; rep(i, q) cout << ans[i] + 1 << '\n'; }