import sys

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

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

for elem in num_list:
    idx = elem[0] - 1 # index
    if idx not in used_dict:
        used_dict[idx] = elem[1]
    elif used_dict[idx] != elem[1]:
        print('-1')
        sys.exit()
    
if 0 in used_dict and used_dict[0] == 0:
    print('-1')
    sys.exit()

for k,v in used_dict.items():
    num_str = num_str[:k] + str(v) + num_str[k+1:]

if num_str[0] == '0' and n >= 2:
    num_str = '1' + num_str[1:]

print(num_str)