## https://yukicoder.me/problems/no/1508 def main(): N, Q = map(int ,input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) win_flag = [0, N - 1] win_flag_list = [] win_flag_list.append(win_flag) for q in reversed(range(Q)): # 遭難者が叩く a = A[q] - 1 b = B[q] - 1 new_win_flag = [0, N - 1] if (a, b) in ((win_flag[0], win_flag[0] + 1), (win_flag[0] + 1, win_flag[0])): new_win_flag[0] = win_flag[0] + 1 elif a == win_flag[0] or b == win_flag[0]: new_win_flag[0] = win_flag[0] else: new_win_flag[0] = max(0, win_flag[0] - 1) if (a, b) in ((win_flag[1], win_flag[1] - 1), (win_flag[1] - 1, win_flag[1])): new_win_flag[1] = win_flag[1] - 1 elif a == win_flag[1] or b == win_flag[1]: new_win_flag[1] = win_flag[1] else: new_win_flag[1] = min(N - 1, win_flag[1] + 1) win_flag = new_win_flag win_flag_list.append(win_flag) if win_flag[0] > win_flag[1]: print("NO") return win_flag_list.reverse() print("YES") actions = [] for i in range(N): if win_flag_list[0][0] <= i <= win_flag_list[0][1]: actions.append(i + 1) i0 = i for q in range(Q): a = A[q] - 1 b = B[q] - 1 for j in range(-1, 2): if 0 <= i0 + j < N: x0, y0 = win_flag_list[q + 1] if x0 <= i0 + j <= y0 and (i0 + j) not in (a, b): actions.append(i0 + j + 1) i0 = i0 + j break break for a in actions: print(str(a)) def main2(): N, Q = map(int ,input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) win_flag = [1] * N win_flag_list = [] win_flag_list.append(win_flag) for q in reversed(range(Q)): # 遭難者が叩く a = A[q] - 1 b = B[q] - 1 win_flag[a] = 0 win_flag[b] = 0 # あなたが今いる駒が勝てそうかどうかの判定 new_win_flag = [-1] * N for i in range(N): is_win = 0 for j in range(-1, 2): if 0 <= i + j < N: is_win |= win_flag[i + j] new_win_flag[i] = is_win win_flag = new_win_flag win_flag_list.append(win_flag) if sum(win_flag) <= 0: print("NO") return win_flag_list.reverse() print("YES") actions = [] for i in range(N): if win_flag_list[0][i] == 1: actions.append(i + 1) i0 = i for q in range(Q): a = A[q] - 1 b = B[q] - 1 for j in range(-1, 2): if 0 <= i0 + j < N: if win_flag_list[q + 1][i0 + j] == 1 and (i0 + j) not in (a, b): actions.append(i0 + j + 1) i0 = i0 + j break break for a in actions: print(str(a)) if __name__ == '__main__': main()