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

ans = 0
l = [-1] * n

for i in range(m):
    digit, num = map(int, input().split())
    if digit == 1 and num == 0 and n != 1:
        ans = -1

    elif l[digit - 1] != -1 and l[digit - 1] != num: 
        ans = -1
    else:
        l[digit - 1] = num

if ans == -1:
    print(ans)
else:
    ans = ''
    if l[0] == -1 and n != 1:
        l[0] = 1
    for i in l:
        if i == -1:
            ans += '0'
        else:
            ans += str(i)

print(ans)

