import sys
n, m = map(int, input().split())

ans = 0
li = [list(map(int, input().split())) for i in range(m)] 

for i in range(m):
    for j in range(m):
        if (li[i][0] == li[j][0]) and (li[i][1] != li[j][1]):
            print(-1)
            sys.exit()

for i in range(m):
    if (li[i][0] == 1) and (li[i][1] == 0) and (n != 1):
        print(-1)
        sys.exit()
        
if n == 1:
    ans = li[0][1]
    print(ans)

elif n == 2:
    for i in range(m):
        if (li[i][0] == 1):
            ans -= (ans//10)*10
            ans += li[i][1]*10
        else:
            ans -= (ans%10)
            ans += li[i][1]
        
        if ans < 10:
            ans += 10
            
    print(ans)

else:
    for i in range(m):
        if (li[i][0] == 1):
            ans -= (ans//100)*100
            ans += li[i][1]*100
        elif (li[i][0] == 2):
            ans -= ((ans-(ans//100)*100)//10)*10
            ans += li[i][1]*10
        else:
            ans -= (ans%10)
            ans += li[i][1]
            
        if ans < 100:
            ans += 100
            
    print(ans)