import numpy as np
n,m=map(int,input().split())
lst_=[]
ary=[]
one=[]
two=[]
three=[]
for i in range(m):
    lst=np.fromstring(input(),int,sep=' ')
    ary.append(lst)
for i in ary:
    if i[0]==1:
        one.append(i[1])
    elif i[0]==2:
        two.append(i[1])
    elif i[0]==3:
        three.append(i[1])
        
for i in [one,two,three]:
    s=set(i)
    if len(s)==1:
        ss=list(s)
        lst_.append(ss[0])
    elif len(s)==0:
        lst_.append(0)
    else:
        print(-1)
        exit()
if n>0 and lst_[0]==0:
    print(-1)
else:
    for i in range(n):
        print(lst_[i],end='')