import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append(list(map(int, input().split())))

minimum = [10]*n

for i in range(m):
    minimum[l[i][0]-1] = min(l[i][1], minimum[l[i][0]-1])


if minimum[n-1] == 10 or (n != 1 and minimum[n-1] == 0):
    print(-1)
    quit()

for i in range(n):
    if minimum[i] == 10:
        minimum[i] = '0'
    else:
        minimum[i] = str(minimum[i])

print(('').join(minimum))