[n,m] = [int(i) for i in input().split()]
dic = {}
checker2 = 1
checker3 = 1
for i in range(m):
    [s,c] = [int(i) for i in input().split()]
    if s-1 in dic.keys() and dic[s-1] != str(c):
        checker2 = 0
    else:
        dic[s-1] = str(c)
#print(dic)
if checker2:
    for i in range(10 ** (n-1)-1,10 ** n):
        checker = 1
        num = str(i)
        for key in dic.keys():
            if key >= len(num):
                checker = 0
            else:
                if dic[key] != num[key]:
                    checker = 0

        if checker:
            checker3 = 0
            print(i)
            break
    if checker3:
        print(-1)

else:
    print(-1)
