N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))
sc.sort()
for i in range(M - 1):
    if sc[i][0] == sc[i + 1][0] and sc[i][1] != sc[i + 1][1]:
        print('-1')
        exit()


max_len = sc[-1][0]
min_idx = sc[0][0]
is_ans = False
for i in range(10 ** (3 - min_idx),1000):
    str_num = str(i)
    num_len = len(str_num)
    for s, c in sc:
        # if num_len max_len:
        #     break
        if int(str_num[s - 1]) != c:
            break
    else:
        is_ans = True
        ans = i
        break
if is_ans:
    print(ans)
else:
    print("-1")
