Toad Ivan has $m$ pairs of integers, each integer is between $1$ and $n$, inclusive. The pairs are $(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$. 

He asks you to check if there exist two integers $x$ and $y$ ($1 \leq x < y \leq n$) such that in each given pair at least one integer is equal to $x$ or $y$.


-----Input-----

The first line contains two space-separated integers $n$ and $m$ ($2 \leq n \leq 300\,000$, $1 \leq m \leq 300\,000$) — the upper bound on the values of integers in the pairs, and the number of given pairs.

The next $m$ lines contain two integers each, the $i$-th of them contains two space-separated integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n, a_i \neq b_i$) — the integers in the $i$-th pair.


-----Output-----

Output "YES" if there exist two integers $x$ and $y$ ($1 \leq x < y \leq n$) such that in each given pair at least one integer is equal to $x$ or $y$. Otherwise, print "NO". You can print each letter in any case (upper or lower).


-----Examples-----
Input
4 6
1 2
1 3
1 4
2 3
2 4
3 4

Output
NO

Input
5 4
1 2
2 3
3 4
4 5

Output
YES

Input
300000 5
1 2
1 2
1 2
1 2
1 2

Output
YES



-----Note-----

In the first example, you can't choose any $x$, $y$ because for each such pair you can find a given pair where both numbers are different from chosen integers.

In the second example, you can choose $x=2$ and $y=4$.

In the third example, you can choose $x=1$ and $y=2$.

Difficulty: interview

Starter code:

Solutions:
from copy import copy
n, m = map(int, input().split())
P = []
z = set()
for i in range(1, n + 1):
    z.add(i)
for i in range(m):
    P.append(list(map(int, input().split())))
for x in P[0][0], P[0][1]:
    s = copy(z)
    for i in range(1, m):
        a, b = P[i]
        if a != x and b != x:
            s.intersection_update({a, b})
    if len(s):
        print('YES')
        return
print('NO')

import sys
# gcd
# from fractions import gcd
# from math import ceil, floor
# from copy import deepcopy
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# fin = open('in_1.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return list(map(int, input().rstrip().split()))
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def __starting_point():

    # write code
    n, m = mi()
    l = [0]*m
    r = [0]*m
    for i in range(m):
        l[i], r[i] = mi()
    lf = l[0]
    rf = r[0]
    flag = True
    for i in range(m):
        if l[i] != lf and r[i] != lf:
            if l[i] != rf and r[i] != rf:
                lf2 = l[i]
                rf2 = r[i]
                flag = False
                break
    if flag:
        print('YES')
        return
    Lis = [lf, rf, lf2, rf2]
    for i in range(3):
        for j in range(i + 1, 4):
            left = Lis[i]
            right = Lis[j]
            for cnt in range(m):
                if l[cnt] != left and r[cnt] != left:
                    if l[cnt] != right and r[cnt] != right:
                        break
            else:
                print('YES')
                return
    print('NO')

__starting_point()

def main():
    def check(x, y):
        for a, b in mas:
            if not((a == x or a == y) or (b == x or b == y)):
                return [a, b]
        return [-1, -1]
    def check1(x, y):
        for a, b in mas:
            if not((a == x or a == y) or (b == x or b == y)):
                return False
        return True
    n, m = list(map(int, input().split()))
    mas = []
    ans = False
    for i in range(m):
        mas.append(sorted(list(map(int, input().split()))))
    k = check(*mas[0])
    if k == [-1, -1]:
        print('YES')
    else:
        ans = check1(mas[0][0], k[0]) or check1(mas[0][0], k[1]) or check1(mas[0][1], k[0]) or check1(mas[0][1], k[1])
        if ans:
            print('YES')
        else:
            print('NO')
main()

from sys import stdin
# stdin=open('input.txt')

def input():
	return stdin.readline().strip()


# from sys import stdout
# stdout=open('input.txt',mode='w+')

# def print1(x, end='\n'):
# 	stdout.write(str(x) +end)


# a, b = map(int, input().split())

# l = list(map(int, input().split()))


# # CODE BEGINS HERE.................
from itertools import permutations, combinations


m, n = list(map(int, input().split()))

pairs = []
for i in range(n):
	a, b = list(map(int, input().split()))
	pairs.append((a, b))

if n == 1:
	print('YES')
else:
	possible = set([pairs[0][0], pairs[0][1]])
	flag = True
	for i in range(n):
		if pairs[i][0] in possible or pairs[i][1] in possible:
			continue
		else:
			if len(possible) == 4:
				flag = False
				break
			else:
				possible.add(pairs[i][0])
				possible.add(pairs[i][1])
	if flag:
		possible = list(possible)
		x_y = list(combinations(possible, 2))
		for x, y in x_y:
			x_y_ = set([x, y])
			flag = True
			for i in range(n):
				if pairs[i][0] in x_y_ or pairs[i][1] in x_y_:
					continue
				else:
					flag = False
					break	
			if flag:
				break

	if flag:
		print('YES')
	else:
		print('NO')

# # CODE ENDS HERE....................
# stdout.close()



n,m=list(map(int, input().split()))
pairs=[tuple(int(x) for x in input().split()) for _ in range(m)]

# print(pairs)
possible={pairs[0], (pairs[0][0], None), (pairs[0][1], None)}
# print(pairs[0], possible)
for p in pairs[1:]:
    add=set()
    remove=set()
    for o in possible:
        if p[0] in o or p[1] in o:
            continue
        remove.add(o)
        if o[1] is None:
            add.add((o[0], p[0]))
            add.add((o[0], p[1]))
    possible = (possible - remove) | add
    # print(p, possible)
    if not possible:
        break

if not possible:
    print('NO')
else:
    print('YES')


# alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 998244353 
# INF = 100_000_000

# from heapq import heappush, heappop
# from collections import defaultdict
# from math import sqrt

t = 1#int(input())

for test in range(t):
    # n = int(input())
    ans = "NO"
    n,m = (((list(map(int, input().split())))))
    arr = []
    for i in range(m):
        a,b = (((list(map(int, input().split())))))
        tmp = [a,b]
        arr.append(tmp)

    x = arr[0][0]
    y = [i for i in range(n+1)]
    y = set(y)
    for pair in arr:
        if x not in pair:
            y = y.intersection(set(pair))
    if len(y)>0:
        ans="YES"

    x = arr[0][1]
    y = [i for i in range(n+1)]
    y = set(y)
    for pair in arr:
        if x not in pair:
            y = y.intersection(set(pair))
    if len(y)>0:
        ans="YES"

    print(ans)
        
        
        





n,m=list(map(int,input().split()))
ms=[]
cnt={}
def cd(x):
    if x in cnt:
        cnt[x]+=1
    else:
        cnt[x]=1
for i in range(m):
    x,y=list(map(int,input().split()))
    ms.append((x,y))
    cd(x)
    cd(y)
ans=[]
for k,v in list(cnt.items()):
    if v>=m//2:
        ans.append(k)
def check_one(c):
    for i in range(m):
        x,y=ms[i]
        if x==c or y==c:
            continue
        if check_two(c,x,i):
            return True
        if check_two(c,y,i):
            return True
        return False
    return True

def check_two(c1,c2,s):
    for i in range(s,m):
        x,y=ms[i]
        if x==c1 or x==c2 or y==c1 or y==c2:
            continue
        else:
            return False
    return True

for a in ans:
    if check_one(a):
        print('YES')
        quit()

print('NO')


import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))

number = [list(map(int, input().split())) for _ in range(m)]
a = number[0][0]
b = number[0][1]
if a > n and b > n:
    print("NO")
else:
    flaga1 = 1
    flaga2 = 1
    flagb1 = 1
    flagb2 = 1
    count = 0
    if a <= n:
        c = a
        d = a
        for i in number:
            if a not in i:
                c = i[0]
                d = i[1]
                break

        for i in number:
            if a not in i and d not in i:
                flaga1 = 0
                break


        for i in number:
            if a not in i and c not in i:
                flaga2 = 0
                break




    if b <= n:
        c = b
        d = b
        for i in number:
            if b not in i:
                c = i[0]
                d = i[1]
                break

        for i in number:
            if b not in i and d not in i:
                flagb1 = 0
                break


        for i in number:
            if b not in i and c not in i:
                flagb2 = 0
                break


    if flaga1 == 0 and flaga2 == 0 and flagb1 == 0 and flagb2 == 0:
        print("NO")
    else:
        print("YES")


from collections import Counter
from itertools import chain
ab = tuple((tuple(map(int, input().split())) for _ in range(int(input().split()[[2, 1][1]]))))
for x_ in Counter(chain(*ab)).most_common(4):
    x = x_[0]
    ab2 = (abi for abi in ab if x not in abi)
    try:
        try:
            ys = set(next(ab2))
        except StopIteration:
            pass
        else:
            for abi2 in ab2:
                ys.intersection_update(abi2)
            assert ys
        print("YES")
        break
    except AssertionError:
        pass
else:
    print("NO")


n, m = map(int, input().split())
res = [set(map(int, input().split())) for _ in range(m)]
a = res[0]
has = False
for i in range(m):
    if not res[i] & a:
        b = res[i]
        has = True
if not has:
    print("YES")
    return
for x in a:
    for y in b:
        fail = False
        for _ in res:
            if x not in _ and y not in _:
                fail = True
        if not fail:
            print("YES")
            return
print("NO")

n,m = map(int, input().strip().split())
can = False
pairs = []
for i in range (m):
    a,b = map(int, input().strip().split())
    pairs.append([a,b])
first = pairs[0][0]
missed = []
for i in range(m):
    if pairs[i][0] != first and pairs[i][1] != first:
        missed.append(i)
if missed != []:
    ind = missed[0]
    second = pairs[ind][0]
    test = True
    for i in range(len(missed)):
        if second != pairs[missed[i]][0] and second != pairs[missed[i]][1]:
            test = False
            break
    if test == True:
        can = True
    second = pairs[ind][1]
    test = True
    for i in range(len(missed)):
        if second != pairs[missed[i]][0] and second != pairs[missed[i]][1]:
            test = False
            break
    if test == True:
        can = True
else:
    can = True
# second half
first = pairs[0][1]
missed = []
for i in range(m):
    if pairs[i][0] != first and pairs[i][1] != first:
        missed.append(i)
if missed != []:
    ind = missed[0]
    second = pairs[ind][0]
    test = True
    for i in range(len(missed)):
        if second != pairs[missed[i]][0] and second != pairs[missed[i]][1]:
            test = False
            break
    if test == True:
        can = True
    second = pairs[ind][1]
    test = True
    for i in range(len(missed)):
        if second != pairs[missed[i]][0] and second != pairs[missed[i]][1]:
            test = False
            break
    if test == True:
        can = True
else:
    can = True
if can ==  True:
    print ('YES')
else:
    print ('NO')

from itertools import combinations

n,m=list(map(int,input().split()))
c=[[] for i in range(n+1)]
p=[]
for i in range(m):
	x,y=list(map(int,input().split()))
	p.append([x,y])


x=p[0]
arr=[x[0],x[1]]
for i in p:
	if len(set(x).intersection(set(i)))==0:
		arr.append(i[0])
		arr.append(i[1])
		break

for i in range(m):
	for j in arr:
		if j in p[i]:
			c[j].append(i)


x=list(combinations(arr,2))
req=[i for i in range(m)]

for i in x:
	n1=i[0]
	n2=i[1]
	if list(set(c[n1]+c[n2]))==req:
		print("YES")
		return

print("NO")


#!/usr/bin/env python3

(n, m) = tuple(map(int, input().split()))

x = []
for i in range(m):
    pair = tuple(map(int, input().split()))
    x.append(pair)

if m == 1:
    print('YES')
    return

s = None
top = x[0][0]
for i in range(1, m):
    if x[i][0] != top and x[i][1] != top:
        if s is None:
            s = set(x[i])
        else:
            s &= set(x[i])
if s is None or len(s) != 0:
    print('YES')
    return

s = None
top = x[0][1]
for i in range(1, m):
    if x[i][0] != top and x[i][1] != top:
        if s is None:
            s = set(x[i])
        else:
            s &= set(x[i])
if s is None or len(s) != 0:
    print('YES')
    return

print('NO')













ure, nre = list(map(int, input().split()))





















lolly = [list(map(int, input().split())) for i in range(nre)]





import sys






















xre = lolly[0][0]













for i in range(nre):
	
	
	
	
	
	
	if( xre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		yre = lolly[i][0]
		
		
		
		
		
		
		
		
		
		
		
		zre = lolly[i][1]
		
		
		
		
		
		
		
		
		j = i
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		break
	
	
	
	
	
	
	
	if( i == nre-1):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		print("YES")
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		return
















kre1 = 1














kre2 = 1















for i in range(j, nre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if( xre not in lolly[i] and yre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		kre1 = 0
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		break





































for i in range(j, nre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if (xre not in lolly[i] and zre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		kre2 = 0
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		break
































import sys

























if( kre1==1 or kre2==1):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	print("YES")
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return



















xre = lolly[0][1]































for i in range(nre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if( xre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		yre = lolly[i][0]
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		zre = lolly[i][1]
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		j = i
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		break













kre1 = 1

















kre2 = 1































for i in range(j, nre):














	if (xre not in lolly[i] and yre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		kre1 = 0
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		break













for i in range(j, nre):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	if (xre not in lolly[i] and zre not in lolly[i]):
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		kre2 = 0
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		break






























import sys








































if( kre1==1 or kre2==1):
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	print("YES")
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return



print("NO")

from sys import stdin
"""
n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
s=list(map(int,stdin.readline().strip().split()))
"""
n,m=list(map(int,stdin.readline().strip().split()))
s=[list(map(int,stdin.readline().strip().split())) for i in range(m)]
a,b=s[0][0],s[0][1]
s1=[]
flag=False
for i in range(len(s)):
    if s[i][0]!=a and s[i][1]!=a:
        s1.append(s[i])
a1=0
b1=0
for i in range(len(s1)):
    if i==0:
        a1,b1=s1[0][0],s1[0][1]

        continue
    if a1!=s1[i][1] and a1!=s1[i][0]:
        a1=-1
    if b1!=s1[i][1] and b1!=s1[i][0]:
        b1=-1

if b1!=-1 or a1!=-1:
    flag=True
s1=[]
for i in range(len(s)):
    if s[i][0]!=b and s[i][1]!=b:
        s1.append(s[i])
a1=0
b1=0
for i in range(len(s1)):
    if i==0:
        a1,b1=s1[0][0],s1[0][1]
        continue
    if a1!=s1[i][1] and a1!=s1[i][0]:
        a1=-1
    if b1!=s1[i][1] and b1!=s1[i][0]:
        b1=-1
     
if b1!=-1 or a1!=-1:
    flag=True   

if flag:
    print("YES")
else:
    print("NO")


n, m = list(map(int, input().split()))
if m <= 2:
    print('YES')
    return
a = list({frozenset(list(map(int, input().split()))) for q in range(m)})
x = list(a[0])[0]
y = list(a[0]-{x})[0]
s = set()
for q in a:
    if x not in q:
        s.add(q)
if len(s) < 2:
    print('YES')
    return
s = iter(s)
x = set(next(s)) & next(s)
if len(x) != 0:
    x = list(x)[0]
    for q in s:
        if x not in q:
            break
    else:
        print('YES')
        return
s = set()
for q in a:
    if y not in q:
        s.add(q)
if len(s) < 2:
    print('YES')
    return
s = iter(s)
y = set(next(s)) & next(s)
if len(y) == 0:
    print('NO')
    return
y = list(y)[0]
for q in s:
    if y not in q:
        print('NO')
        break
else:
    print('YES')


from collections import Counter
n, m = list(map(int, input().split()))
cp = []
for i in range(m):
    cp.append(list(map(int, input().split())))
v1, v2 = cp[0][0], cp[0][1]
m1, m2 = [], []
for i in range(1, m):
    if v1 not in cp[i]:
        m1.append(cp[i])
    if v2 not in cp[i]:
        m2.append(cp[i])
used = [[], [], [], []]
if (len(m1) < 2) | (len(m2) < 2):
    print('YES')
else:
    v1, v2 = m1[0][0], m1[0][1]
    for i in range(1, len(m1)):
        if v1 not in m1[i]:
            used[0].append(0)
        else:
            used[0].append(1)
        if v2 not in m1[i]:
            used[1].append(0)
        else:
            used[1].append(1)

    v1, v2 = m2[0][0], m2[0][1]
    for i in range(1, len(m2)):
        if v1 not in m2[i]:
            used[2].append(0)
        else:
            used[2].append(1)
        if v2 not in m2[i]:
            used[3].append(0)
        else:
            used[3].append(1)
    b = False
    for i in range(4):
        if Counter(used[i])[0] == 0:
            b = True
            break
    if b:
        print('YES')
    else:
        print('NO')


import sys

n, m = list(map(int, input().split()))
a, b = list(map(int, input().split()))
pool = [a, b]
pairs = [(a,b)]
for _ in range(m-1):
    a, b = list(map(int, input().split()))
    if a not in pool and b not in pool:
        pool.append(a)
        pool.append(b)
    pairs.append((a, b))
    if len(pool) >= 5:
        print("NO")
        return
count = 0
for i in range(len(pool) - 1):
    for j in range(i+1, len(pool)):
        x = [pool[i], pool[j]]
        for k in pairs:
            if k[0] != x[0] and k[0] != x[1] and k[1] != x[0] and k[1] != x[1]:
                count += 1
                break

if count != len(pool) * (len(pool) - 1) // 2:
    print("YES")
else:
    print("NO")


n, m = list(map(int, input().split()))

a, b = list(map(int, input().split()))
ar1 = [a]
ar2 = [b]

lst = [[a, b]]
for i in range(m - 1):
    lst.append(list(map(int, input().split())))

ar3 = [0, 0]
ar4 = [0, 0]
for a, b in lst:
    if len(ar1) == len(ar2) == 2:
        break
    if len(ar1) != 2 and a not in ar1 and b not in ar1:
        ar1.append(a)
        ar3 = [ar1[0], b]
    if len(ar2) != 2 and a not in ar2 and b not in ar2:
        ar2.append(a)
        ar4 = [ar2[0], b]

ans = 'NO'
flag1, flag2, flag3, flag4 = 0, 0, 0, 0
for a, b in lst:
    if a not in ar1 and b not in ar1:
        flag1 = 1
    if a not in ar2 and b not in ar2:
        flag2 = 1
    if a not in ar3 and b not in ar3:
        flag3 = 1
    if a not in ar4 and b not in ar4:
        flag4 = 1

if flag1 == 0 or flag2 == 0 or flag3 == 0 or flag4 == 0:
    ans = 'YES'
print(ans)


n,m=[int(x) for x in input().split()]
pairs=[]
for i in range(m):
    a=([int(x) for x in input().split()])
    pairs.append(a)
x,y=pairs[0][0],pairs[0][1]
for item in pairs:
    if item[0]!=x and item[0]!=y and item[1]!=x and item[1]!=y:
        a,b,c,d=x,y,item[0],item[1]
        break
else:
    a,b,c,d=x,y,x,y
for x,y in (a,b),(a,c),(b,d),(c,d),(a,d),(b,c):
    for item in pairs:
        if item[0]!=x and item[1]!=x and item[0]!=y and item[1]!=y:
            break
    else:
        print('YES')
        break
else:
    print('NO')


import sys
from collections import defaultdict
input = sys.stdin.readline


class Problem:
    def __init__(self):
        pass

    def solve(self):
        print(self._solve())

    def _solve(self):
        n, m = [int(item) for item in input().split()]
        pairs = []
        cnt = {}
        mp = defaultdict(int)
        for i in range(m):
            pair = sorted([int(item) for item in input().split()])
            pairs.append(pair)
            mp[pair[0]] += 1
            mp[pair[1]] += 1
            pair = tuple(pair)
            if pair in cnt:
                cnt[pair] += 1
            else:
                cnt[pair] = 1

        res = []

        for x in mp:
            res.append([mp[x], x])
        res.sort()
        for i in range(len(res) - 1, -1, -1):
            for j in range(len(res) - 1, i, -1):
                if res[i][0] + res[j][0] < m:
                    break
                pair = tuple(sorted([res[i][1], res[j][1]]))
                if pair[0] == pair[1]:
                    continue
                if not pair in cnt:
                    occs = 0
                else:
                    occs = cnt[pair]
                # print(pair, res[i][0], res[j][0], occs)
                if res[i][0] + res[j][0] - occs == m:
                    # return ' '.join(str(x) for x in sorted([res[i][1], res[j][1]]))
                    return "YES"
        return "NO"


def main():
    problem = Problem()
    problem.solve()


def __starting_point():
    main()

__starting_point()

import sys
N, M = map(int, input().split())
P = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
#P = [list(map(int, input().split())) for _ in range(M)]
idx = P[0][0]
S = set()
for i, (a, b) in enumerate(P):
    if a == idx or b == idx:
        continue
    break
else:
    print('YES')
    return
S = set([P[i][0], P[i][1]])
for a, b in P[i:]:
    if a == idx or b == idx:
        continue
    S.intersection_update(set([a, b]))
    if not S:
        break
else:
    print('YES')
    return
idx = P[0][1]
S = set()
for i, (a, b) in enumerate(P):
    if a == idx or b == idx:
        continue
    break
else:
    print('YES')
    return
S = set([P[i][0], P[i][1]])
for a, b in P[i:]:
    if a == idx or b == idx:
        continue
    S.intersection_update(set([a, b]))
    if not S:
        break
else:
    print('YES')
    return
print('NO')

from sys import stdin
input=stdin.readline
n,m=map(int,input().split())
d = []
for i in range(m):
    d.append(list(map(int,input().split())))
x=d[0][0]
y=d[0][1]
c=[]
e=[]
g=[]
for i in d:
    if x in i:
        c.append(i)
    if y in i:
        e.append(i)
    if x not in i and y not in i:
        g.append(i)
if len(g)==0:
    print('YES');return
s=set(g[0])
for i in g:
    s=s.intersection(set(i))
if len(s)==0:
    print('NO');return
k=list(s)
for s in k:
    fl1=fl2=1
    for i in c:
        if s not in i and y not in i:
            fl1=0
            break
    for i in e:
        if s not in i and x not in i:
            fl2=0
            break
    if fl1 or fl2:
        print('YES');return
print('NO')


n, m = list(map(int, input().split()))
a = []
b = []
y = -1
for i in range(m):
    a.append(list(map(int, input().split())))
    b.append(set(a[-1]))
    if i >= 1 and y == -1:
        if not b[0]&b[-1]:
            y = i
if m <= 2 or y == -1:
    print('YES')
else:
    c, d, e, f = *a[0], *a[y]
    #print(c, d, e, f, a[0], a[y], y)
    x = [{c, e}, {c, f}, {d, e}, {d, f}]
    z = [True, True, True, True]
    for pair in b:
        for zp in [0,1,2,3]:
            z[zp] = z[zp] if pair&x[zp] else False
            #print(zp, z, x, pair, pair&x[zp])
    if z[0] or z[1] or z[2] or z[3]:
        print('YES')
    else:
        print('NO')