N, M = list(map(int, input().split()))
sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
    
num = "a" * N

for i in range(M):
    if num[sc[i][0]-1] == "a":
        num = num[:sc[i][0]-1] + str(sc[i][1]) + num[sc[i][0]:]
    else:
        if num[sc[i][0]-1] == str(sc[i][1]):
            continue
        else:
            print(-1)
            break

        
else:
    if num[0] == "0":
        print(-1)
    else:
        num = num.replace("a", "0")
    
        print(num)
    