n,m = list(map(int,input().split()))
ans = ''
l = ['a']*n
for i in range(m):
    s,c = list(map(int,input().split()))
    if l[s-1] != 'a' and l[s-1] != str(c):
        ans = str(-1)
    else:
        l[s-1] = str(c)
if l[0] == 0:
    ans = str(-1)
if l[0] == 'a':
    l[0] = str(1)
if n >=2:
    if l[1] == 'a':
        l[1] = str(0)
if n >=3:
    if l[2] == 'a':
        l[2] = str(0)
if ans != '-1':
    ans = ''
    for j in range(n):
        ans += l[j]
       
print(int(ans))