import sys

N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
X = 0
Y = 0
flag = 0

if N == 1:
    X = 9
    Y = 0
elif N == 2:
    X = 99
    Y = 10
else:
    X = 999
    Y = 700

for j in range(Y, X+1):
    for k in range(M):
        if int(str(j)[s[k]-1]) != c[k]:
            flag += 1
    if flag == 0:
        print(j)
        sys.exit()
    else:
        flag = 0

print(-1)