n, m =map(int,input().split())
a = [-1] * n
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
if a[0] == 0:
    flg = False
elif a[0] == -1 and n >= 2:
    a[0] = 1
elif a[0] == -1 and n == 1:
    a[0] = 0
    
if flg:
    num = 0
    for i in range(len(a)):
        if a[i] != -1:
            num += a[i] * (10**(n-i-1))
    print(num)
else:
    print(-1)