#ABC157 C - Guess The Number

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

ans = ['']*3
flag = True
for i in range(M):
    s,c = map(int,input().split(' '))
    if(ans[s-1] == '' or ans[s-1] == str(c)):
        ans[s-1] = str(c)
    else:
        flag = False

if(ans[0] == '0' and N > 1):
    flag = False
#print(flag)
#print(ans)

ansint = 0
if(flag == True):
    for i in range(M):
        if (ans[i] != ''):
            ansint += int(ans[i])*10**(M-i-1)
        elif (ans[i] == '' and i == 0):
            ansint += 10**(M-1)
    print(ansint)
else:
    print(-1)
