n, m = map(int, input().split())
ans = ["0", "0", "0"]
flag = True
ansnum = ""
for i in range(m) :
    num = [int(i) for i in input().split()]
    if ans[num[0]-1] == "0" :
        ans[num[0]-1] = num[1]
    elif ans[num[0]-1] == num[1] :
        continue
    else :
        flag = False
        
if n == 2 :
    if ans[0] == 0 :
        flag = False
    elif ans[0] == "0" :
        ans[0] = 1
if n == 3 :
    if ans[0] == 0 :
        flag = False
    elif ans[0] == "0" :
        ans[0] = 1
        
if flag == True :
    for j in range(3) :
        ansnum = ansnum + str(ans[j])
    print(ansnum)
else :
    print(-1)