import sys

n,m = map(int,input().split())
num_list = [list(map(int,input().split())) for _ in range(m)]

if n == 1:
    min_num = 0
    max_num = 9
elif n == 2:
    min_num = 10
    max_num = 99
else:
    min_num = 100
    max_num = 999

for i in range(min_num,max_num+1):
    num_str = str(i)
    count = 0
    for elem in num_list:
        idx = elem[0]-1
        if num_str[idx] == str(elem[1]):
            count += 1
        else:
            break
    if count == n:
        print(num_str)
        sys.exit()


print('-1')