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())

sw = [[0]*2]*m
num = [0]*m
ans = 0
ss = [0]*m
for i in range(m):
    if s[i] == 1 and c[i] == 0:
        ans = 1
        break
    if sw[s[i]-1][0] == 1 and sw[s[i]-1][1] - 1 != c[i]:
        ans = 1
        break
    ss[s[i]-1] = c[i]
    sw[s[i]-1][0] = 1
    sw[s[i]-1][1] = c[i] + 1
if ans ==1:
    print(-1)
else:
    for i in range(m):
        print(ss[i], end="")
    print()