n,m = map(int, input().split())
S = []
C = []
for i in range(m):
    s,c = map(int, input().split())
    S.append(s)
    C.append(c)

flag = True
x = 0

for i in range(1000):
    x = i
    d = []
    flag = True
    if x == 0:
        d.append(x)
    while x != 0:
        num = x % 10
        d.append(num)
        x = x // 10
    d = d[::-1]
    for j in range(m):
        try:
            if d[S[j]-1] == C[j]:
                pass
            else:
                flag = False
        except IndexError:
            flag = False
    if flag:
        x = i
        break
print(x if flag else -1)