n,m = map(int,input().split())
digit = [0]*(m)
value = [0]*(m)
for i in range(m):
    digit[i],value[i] = map(int,input().split())

#全探索
ans = 0
for i in range(keta, 10**3):
    s = str(i)
    if len(s)!=n: continue
    for j in range(m): 
        if int(s[digit[j]-1]) != value[j]:
            break
    else:
        print(i)
        exit()
print('-1')