n,m = map(int,input().split())
ans = list()
sc_list = [set(map(int,input().split())) for _ in range(m)]
for num in range(pow(10,n)):
    for sc in sc_list:
        s,c = sc
        if int(num / pow(10,n-s)) % 10 != c:
            break
    else:
        print(num)
        break
else:
    print('-1')