num_digit, num_cond = map(int, input().split())
conds = ['o'] * (num_digit + 1)
for _ in range(num_cond):
    digit, val = map(int, input().split())
    if (conds[digit] != 'o' and conds[digit] != val) or (num_digit != 1 and digit == 1 and val == 0):
        print(-1)
        exit()
    conds[digit] = val
for cnd in range(1000):
    if len(str(cnd)) != num_digit:
        continue
    tmp = '{0:04d}'.format(cnd)
    is_ans = True
    for idx in range(1, num_digit+1):
        if conds[idx] != 'o' and str(conds[idx]) != tmp[idx]:
            is_ans = False
            break
    if is_ans:
        print(cnd)
        exit()
print(-1)