n, m = tuple([int(i) for i in input().strip().split(" ")])



d = {}

for i in range(m):
    s, c = tuple([int(i) for i in input().strip().split(" ")])
    if s in d:
        d[s].append(c)
    else: 
        d[s] = [c]

def pow10(n):
    r = 1
    for i in range(n):
        r = r * 10
    return r

for i in range(pow10(n-1), pow10(n)):
    si =  str(i)

    flag = True
    for key, values in d.items():
        for value in values:
            if  int(si[key-1]) != value:
                flag = False
                break
    if flag:
        print(i)
        import sys
        sys.exit(0)


print(-1)
    

            

    

