stdin = open(0).read().split('\n')
N, M = map(int,stdin[0].split())
if N==0:
    l=['0']
    for j in range(M):
        s, c = stdin[j+1].split()
        if l[int(s)-1]!=c:flag=False
    if flag:
        print(i)
        exit()
else:
    for i in range(10**(N-1),10**N):
        l=[str(i)[_] for _ in range(len(str(i)))]
        flag=True
        for j in range(M):
            s, c = stdin[j+1].split()
            if l[int(s)-1]!=c:flag=False
        if flag:
            print(i)
            exit()
print(-1)  