import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int n, m; readV(n, m); int[] a; readA(n, a); auto g = Graph!int(n); foreach (_; 0..m) { int u, v; readV(u, v); --u; --v; g.addEdgeB(u, v); } foreach (i; 0..n) { auto b = a.indexed(g[i]); auto v1 = b.filter!(bi => bi > a[i]).array; auto v2 = b.filter!(bi => bi < a[i]).array; if (v1.sort().uniq.walkLength >= 2 || v2.sort().uniq.walkLength >= 2) { writeln("YES"); return; } } writeln("NO"); } struct Graph(N = int) { alias Node = N; Node n; Node[][] g; alias g this; this(Node n) { this.n = n; g = new Node[][](n); } void addEdge(Node u, Node v) { g[u] ~= v; } void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; } }