import sys

N, M = map(int, input().split())
s = []
c = []
for _ in range(M):
    s1, c1 = map(int, input().split())
    s.append(s1)
    c.append(str(c1))


for i in range(1000):
    st = str(i)
    if N != len(st):
        continue
    for j in range(M):
        if st[s[j]-1] != c[j]:
            break
        if j == M-1: 
            print(i)
            sys.exit()
print(-1)