N=int(input()) A=list(map(int,input().split())) E=[[0]*3 for i in range(3)] E[A[2]][A[1]]=1 E[A[2]][A[3]]=1 E[A[2]][A[4]]=1 E[A[0]][A[5]]=1 for i in range(3): if E[i][i]==1: print('NO') exit() for j in range(3): if E[i][j]==1 and E[j][i]==1: print('NO') exit() if E[i][j]==1 and N==0: print('NO') exit() for k in range(3): if E[i][j]==1 and E[j][k]==1 and E[k][i]==1: print('NO') exit() if E[i][j]==1 and E[j][k]==1 and N==1: print('NO') exit() if A[0]==A[1]: print('YES') exit() print('YES')