#C

n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
s = [l[i][0] for i in range(m)]
c = [l[i][1] for i in range(m)]

t = True
a = [0] * n

for i in range(m):
    if a[s[i]-1] == 0 or a[s[i]-1] == c[i]:
        a[s[i]-1] = c[i]
    else:
        t = False
        break
        
#print(a)
if n != 1 and a[0] == 0:
    t = False
if t:
    print("".join(map(str,a)))
else:
    print("-1")