import sys,collections from operator import itemgetter sys.setrecursionlimit(10**7) def Is(): return [int(x) for x in sys.stdin.readline().split()] def Ss(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def S(): return input() n,m = Is() As = Is() g = [[] for i in range(n+1)] for i in range(m): u,v = Is() g[u].append(v) g[v].append(u) for i,a in enumerate(As): if len(g[i+1]) >= 2: lis = [a] + g[i+1] if (min(lis) == a or max(lis) == a) and min(lis) != max(lis): print("YES") exit() print("NO")