import
java.util.ArrayList;
import
java.util.Comparator;
import
java.util.HashMap;
public
class
GFG {
static
boolean
flag =
false
;
static
HashMap<Integer, Integer> mp
=
new
HashMap<Integer, Integer>();
static
class
Graph {
int
V;
int
counter;
ArrayList<Integer> adj[];
@SuppressWarnings
(
"unchecked"
)
Graph(
int
V)
{
this
.V = V;
adj =
new
ArrayList[V +
1
];
for
(
int
i =
0
; i <= V; i++)
adj[i] =
new
ArrayList<Integer>();
}
void
addEdge(
int
u,
int
v)
{
adj[u].add(v);
adj[v].add(u);
}
void
DFS(
int
v,
int
Perm[])
{
counter++;
if
(counter == V) {
flag =
true
;
return
;
}
for
(Integer i : adj[v]) {
if
(i == Perm[counter])
DFS(i, Perm);
}
}
}
static
boolean
checkPermutation(
int
N,
int
M,
int
[][] V,
int
P[])
{
Graph G =
new
Graph(N);
for
(
int
i =
0
; i < M; i++)
G.addEdge(V[i][
0
], V[i][
1
]);
for
(
int
i =
0
; i < N; i++)
mp.put(P[i], i);
for
(
int
i =
1
; i <= N; i++)
G.adj[i].sort((a, b) -> a - b);
G.DFS(P[
0
], P);
return
flag;
}
public
static
void
main(String[] args)
{
int
N =
3
, M =
2
;
int
[][] V = { {
1
,
2
}, {
2
,
3
} };
int
P[] = {
1
,
2
,
3
};
if
(checkPermutation(N, M, V, P))
System.out.println(
"YES"
);
else
System.out.println(
"NO"
);
}
}