n,m = map(int, input().split( ))
dic = {}
#衝突
for i in range(m):
    si,ci = map(int, input().split( ))
    if si in dic:
        if ci!=dic[si]:
            print(-1)
            exit()
    else:
        dic[si]=ci
#2桁以上で最上位ゼロか
if n>1 and 1 in dic:
    if dic[1]==0:
        print(-1)
        exit()
#n=1の処理
if n==1:
    for si in dic:
        print(dic[si])
        exit()

for i in range(10**(n-1),10**n):
    j = str(i)
    flag = True
    for k in range(1,4):
        if k in dic:
            if int(j[k-1])==dic[k]:
                continue
            else:
                flag = False
                break  
    if flag:
        print(i)
        exit()