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

number = "0"*n
degit ={}
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if s in degit:
        if c != degit[s]:
            flg = False
            break
        else:
            next
    else:
        degit[s] = c

for i in range(1,n+1):
    if i in degit:
        number = number[:i-1] + str(degit[i]) + number[i:]
        
if flg:
    print(number)
else:
    print(-1)