#!/usr/bin/env python # -*- coding: utf-8 -*- def memoize(f): cache = {} def helper(*args): if args not in cache: cache[args] = f(*args) return cache[args] return helper import sys import copy from operator import itemgetter import itertools from time import sleep import random @memoize def eval(a, b, c): if a == b or b == c or a == c: return False return max(a, b, c) == b or min(a, b, c) == b l = sys.stdin.readline().split(' ') N = int(l[0]) M = int(l[1]) a = [] l = sys.stdin.readline().split(' ') path = {} can = [] for i in xrange(N): a.append(int(l[i])) path[i+1] = [] can.append([i+1]) u = [] v = [] for i in xrange(M): l = sys.stdin.readline().split(' ') u.append(int(l[0])) v.append(int(l[1])) for i, j in zip(u, v): path[i].append(j) path[j].append(i) count = 0 while True: count += 1 if len(can) == 0: break if count > N*N: break newcan = [] for c in can: if len(c) == 3: if eval(a[c[0]-1], a[c[1]-1], a[c[2]-1]): print "YES" sys.exit(0) else: try: p = random.choice(path[c[-1]]) c.append(p) newcan.append([p]) # del path[c[-2]][0] newcan.append(c) except IndexError: pass newcan.sort() if can == newcan: break can = list(newcan for newcan,_ in itertools.groupby(newcan)) print "NO"