n,m=map(int,input().split())
ary=[]
ans=[]
for i in range(m):
    lst=input().split()
    ary.append(lst)
for i in range(1000):
    for j in ary:
        if str(i)[j[int(0)]]==j[1]:
            ans.append(i)
try:
    print(ans[0])
except:
    pprint(-1)