#!/usr/bin/env python3
import sys

f = sys.stdin
N, M = map(int, f.readline().split(' '))
sc = [list(map(int, f.readline().split(' '))) for _ in range(M)]

result = 0
number = {}
for s, c in sc:
    try:
        if number[str(s)] != c:
            result = -1
            break
    except Exception:
        number[str(s)] = c

if result == -1:
    print(result)
else:
    for i in range(N):
        if i == 0 and (str(i+1) not in number or number[str(i+1)] == 0):
            result = -1
            break
        if str(i+1) not in number:
            number[str(i+1)] = 0
    if result == -1:
        print(result)
    else:
        print(''.join(str(number[str(i+1)]) for i in range(N)))