n, m = map(int, input().split())
slist = []
clist = []

def check(numlist, slist, clist):
    for i in range(m):
        if int(numlist[slist[i]]) != clist[i]:
            return False
    return True

for i in range(m):
    s,c = map(int, input().split())
    slist.append(s-1)
    clist.append(c)
flag = 0
if m > n:
    print(-1)
else:
    for num in range(10**(n-1), 10**n):
        numstring = str(num)
        numlist = list(numstring)
        if check(numlist, slist, clist):
            print(num)
            flag = 1
            break
    if not flag:
        print(-1)

