n, m = map(int, input().split())
rule = [list(map(int, input().split())) for _ in range(m)]
for i in range(1, 10**3):
    s = str(i)
    s_zero = s.zfill(3)
    ans_flag = 1
    for r in rule:
        if s_zero[r[0]-1] != str(r[1]) or (r[0] == 1 and r[1] == 0):
            ans_flag = 0
            break
    if ans_flag == 1:
        print(i)
        exit()
print(-1)
