n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    line = list(map(int, input().split()))
    s.append(line[0])
    c.append(line[1])
for i in range(10**(n-1), 10**n):
    flag = 0
    flag2 = 0
    for j in range(m):
        if str(i)[s[j]-1] != str(c[j]):
            flag = 1
    if flag == 0:
        print(i)
        flag2 = 1
        break
if flag2 == 0:
    print(-1)