# 入力
n,m = map(int,input().split())
ans = 0

l = [-1]*n
for i in range(m):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and n > 1:
        ans = -1
    if l[s-1] == -1 or l[s-1] == c:
        l[s-1] = c
    else:
        ans = -1

if ans >= 0:
    a = ""
    if l[0] == -1 and n != 1:
        a += "1"
    elif l[0] == -1 and n == 1:
        a += "0"
    else:
        a += str(l[0])
    for i in l:
        if i == -1:
            a += str(0)
        else:
            a += str(i)
    ans = int(a)

print(ans)