N, M = map(int, input().split())
s_c = []
for _ in range(M):
    s_c.append(list(map(int, input().split())))

def check(num, s_c):
    num = str(num)
    flag = True
    for s,c in s_c:
        if s>len(num):
            flag = False
        elif not num[s-1] == str(c):
            flag = False
    return flag

a = False
b = True
for i in range(1000):
    a = check(i, s_c)
    if a:
        print(i)
        b = True
        break
if b:
    print(-1)