n,m=map(int,input().split())
digit = [0]*(m+1)
value = [0]*(m+1)
for i in range(1,m+1):
    digit[i],value[i] = map(int,input().split())
res = 0
for i in range(1,n+1):
    if i in digit:
        idx = digit.index(i)
        res += value[idx] * 10**(n-i)
for i in range(1,m+1):
    if int(str(res)[digit[i]-1]) != value[i]:
        print('-1')
        exit()
print(res if len(str(res))==n else '-1')