n, m = map(int,input().split())
dig = [0 for i in range(n)]
ans = ''
flag = 0
for i in range(m):
    s,c = map(int,input().split())
    if s == 1 and c ==0 :
        flag=1
    if dig[(s-1)] != 0 and c != dig[(s-1)]:
        flag=1
        break
    dig[(s-1)] = c
for i in range(n):
    if i == 0:
        if dig[i] != 0:

            ans += str(dig[i])
        else:
            ans += str(1)

    else:
        ans += str(dig[i])
if flag == 0:
    print(ans)
elif flag ==1:
    print('-1')
