N,M = map(int,input().split())
sc = []
for _ in range(M):
    x = list(map(int,input().split()))
    sc.append(x)
if N == 3:
    ll = 1000
    ls = 100
elif N == 2:
    ll = 100
    ls = 10
elif N == 1:
    ll = 10
    ls = 1
ans = -1
for i in range(ls,ll):
    x = str(i)
    check = 1
    for j in sc:
        s = j[0]
        c = j[1]
        if int(x[s-1]) != c:
            check = 0
            break
    #print(i,check) 
    if check == 1:
        ans = i
        break
print(ans)
    
