fla = 0

ans = 0
ket , kaz = map(int,input().split())
num = [-1 for i in range(ket)]
for j in range(kaz):
    s , c = map(int,input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        fla = -1
        break

if fla == 0:
    if num[0] == 0:
        fla = -1
    elif num[0] == -1:
        if ket == 1:
            num[0] = 0
        elif ket != 1:
            num[0] = 1

if fla == 0:
    for i in range(ket-1):
        if num[i+1] == -1:
            num[i+1] = 0
            
if fla == 0:
    for h in range(ket):
        ans +=  num[h]*(10**(ket-h-1))
    print(ans)
elif fla == -1:
    print(-1)