N,M = [int(x) for x in input().split()]
scs = [[int(x) for x in input().split()] for _ in range(M)]

def search(scs):
    for i in range(10**(N-1),1000):
        cnt = 0
        for s,c in scs:
            if str(i)[s-1]==str(c):
                cnt +=1
        if cnt == len(scs):
            return i
    return -1
    
print(search(scs))