n,m = map(int,input().split())
maxn = 10**n
cd = []
isOk = True
for i in range(m):
    x,y = map(int,input().split())
    if(x > n):
        isOk = False
        break

    if([x,y] in cd):
        continue
    for a,b in cd:
        if(a==x):
            isOk=False
    cd.append([x,y])

word = ['0']*n
if(not isOk):
    print(-1)
else:
    for x,y in cd:
        word[x-1] = str(y)
    if(word[0]=='0'):
        if(n==1):
            print(0)
        else:
            print(-1)
    else:
        print(''.join(word))
