n,m = map(int,input().split())
digit = ['0']*n
for i in range(m):
    s,c = input().split()
    s = int(s)
    if digit[s-1] == '0' or digit[s-1] == c:
        digit[s-1] = c
    else:
        digit[s-1] = '-1'
if ('-1' in digit) or (len(digit)!=1 and digit[0] == '0'):
    print(-1)
else:
    print("".join(digit))