# coding: utf-8
# Your code here!

N,M = [int(i) for i in input().split()]


numbers = [0] * N
flags = [False] * N

for _ in range(M):
    s,c = input().split()
    s = int(s)
    if flags[s-1]:
        numbers[s-1] = min(c, numbers[s-1])
    else:
        numbers[s-1] = c

if len(numbers) > 1 and numbers[0] == 0:
    print(-1)
else:
    numbers = [str(i) for i in numbers]
    print(''.join(numbers))
