N,M = map(int,input().split())

number = {i+1:None for i in range(N)}

ans = True

for i in range(M):
    s,c = map(int,input().split())
    if number[s] != None and number[s] != c:
        ans = False
    else:
        number[s] = c

if number[1] == 0:
    ans = False

if ans:
    if number[1] == None:
        n = str(1)
    else:
        n = str(number[1])
    for i in range(1,N):
        if number[i+1] == None:
            n += '0'
        else:
            n += str(number[i+1])
    print(n)
else:
    print(-1)
