from bisect import * N,M = map(int,input().split()) A = list(map(int,input().split())) UV = [list(map(int,input().split())) for _ in range(M)] E = [set() for _ in range(N)] for u, v in UV: u -= 1 v -= 1 E[u].add(A[v]) E[v].add(A[u]) for i in range(N): E[i] = sorted(list(E[i])) for i in range(N): n = len(E[i]) if n < 2: continue x = bisect_left(E[i],A[i]) if x > 1: print("YES") exit() x = bisect(E[i],A[i]) if n - x > 1: print("YES") exit() print("NO")