import sys
N,M =map(int, input().split())
if M == 0:
    print(0)
    sys.exit()
a = [input().split() for l in range(M)]

for i in range(1000):
    flag = 1
    for j in range(M):
        b = str(i)
        if len(b)!= N:
            flag = 0
            continue
        if b[int(a[j][0])-1] != a[j][1]:
            flag = 0
            break
    if flag == 1:
        print(i)
        sys.exit()
print("-1")