n, m = map(int, input().split())

s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())

num = 0
t = 0

if s == 1:
    for i in range(m-1):
        if c[i] != c[i+1]:
            print(-1)
            break
    print(c[0])
else:
    if len(set(s)) != len(s):
        for i in range(m-1):
            if s[i] == s[i+1] and c[i] != c[i+1]:
                #print(-1)
                t = 1
                break

        m = len(set(s))
        s = list(set(s))
        c = list(set(c))

    for i in range(m):
        
        num += 10**(n-s[i])*c[i]
    if t == 0 and num >= 10**(n-1)-1:
        
    	print(num)
    else :
        print(-1)