N,M = map(int,input().split())
SC = []
for _ in range(M):
    sc = list(map(int,input().split()))
    SC.append(sc)
#print(SC)

for num in range(1000):
    ans = True
    znum = str(num).zfill(3)
    #print(znum)
    for sc in SC:
        if znum[sc[0]-1] != str(sc[1]):
            ans = False
    if ans:
        if len(str(num)) == N:
            print(num)
            #print(znum)
            exit()
print(-1)
