import sys
lines = sys.stdin.readlines()
digits = int(lines[0].split()[0])
n = int(lines[0].split()[1])
 
nums = [l.split() for l in lines[1:n]]
result = ['0'] * digits
 
digit_set = set()
for num in nums:
    num_index = int(num[0])-1
    num_value = num[1]
    if num_index in digit_set and result[num_index] != num_value:
        print(-1)
        break
    digit_set.add(num_index)
    result[num_index] = num_value
else:
    if digits > 1 and result[0] == '0':
        print(-1)
    else:
        print(''.join(result))