from operator import itemgetter

n, m = map(int, input().split())

if m == 0:
    f = '1'
    for i in range(n-1):
        f += '0'
    print(f)
    exit()

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

f = ''
last = 1
digit = 0
number = True

if sc[0][0] != 1:
    f += '1'
    last = sc[0][0]
else:
    if sc[0][1] == 0:
        number = False
    f += str(sc[0][1])

digit = int(f)

for i in  range(1, m):
    if sc[i][0] == 1 and sc[i][1] == 0:
        number = False
        
    if sc[i-1][0] == sc[i][0]:
        if digit != sc[i][1]:
            number = False
        else:
            continue
            
    elif sc[i][0] > last + 1:
        f += '0'
        last = sc[i][0]
        digit = 0
    f += str(sc[i][1])
    last = sc[i][0]
    digit = sc[i][1]

if number:
    print(f)
else:
    print(-1)