import sys

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

for _ in range(n):
    num_str += '0'

for elem in num_list:
    idx = elem[0] - 1 # index
    if idx == 0 and elem[1] == 0:
        print('-1')
        sys.exit()
    if num_str[idx] == '0':
        num_str = num_str[:idx]+str(elem[1])+num_str[idx+1:]
    if num_str[idx] != str(elem[1]):
        print('-1')
        sys.exit()
    
if num_str[0] == '0' and n >= 2:
    num_str = '1' + num_str[1:]

print(num_str)