n,m
=
map
(
int
,
input
().split())
dices
=
[[
-
1
]]
+
[[
-
1
,
3
,
5
,
1
,
2
,
6
,
4
]
for
_
in
range
(n)]
def
top(dice):
return
dice[
3
]
def
front(dice):
dice[
1
],dice[
3
],dice[
6
],dice[
5
]
=
dice[
5
],dice[
1
],dice[
3
],dice[
6
]
def
right(dice):
dice[
2
],dice[
3
],dice[
4
],dice[
5
]
=
dice[
5
],dice[
2
],dice[
3
],dice[
4
]
for
i
in
range
(m):
a,b
=
map
(
int
,
input
().split())
if
b>
0
: dices[a],dices[b]
=
dices[b],dices[a]
#swap(dices[a],dices[b])
elif
b
=
=
-
1
: front(dices[a])
elif
b
=
=
-
2
: right(dices[a])
for
i
in
range
(
1
,n
+
1
):
print
(top(dices[i]),end
=
' '
)
print
()