N, M = map(int, input().split())
P = [list(map(int,input().split())) for i in range(M)]

ans = -1

for x in range(700, 704):
    if len(str(x)) != N: 
        continue
    else:
        count = 0
        s = str(x)
        for p in P:
            if int(s[int(p[0]) - 1]) == p[1]:
                count += 1
        if count == M:
            ans = x
            break

print(ans)
