n,m =map(int,input().split())
ans = 0
l1 = []
l2 = []
for i in range(m):
    s,c =map(int,input().split())
    if s in l1 and c != l2[l1.index(s)]:
        print('-1')
        exit()
    elif s in l1 and c == l2[l1.index(s)]:
        continue
    else:
        ans += c*10**(s-1)
        l1.append(s)
        l2.append(c)
ans = str(ans)[::-1]

if n == len(ans):
    print(ans)
else:
    x = str(10**(n-len(ans) -1))
    print(x+ans)