n,m = map(int,input().split())
li = [0]*n
f = 1
for i in range(m):
    a,b = map(int,input().split())
    if li[a-1] == 0 or li[a-1] == b:
        li[a-1] = b
    else:
        print(-1)
        f = 0
        break
lia = (str(s) for s in li)
if li[0] == 0:
    f = 0
    print(-1)
if f == 1:
    print("".join(lia))