# import numpy as np
import sys
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
# map(int, input().split())
# list(map(int, input().split()))
 
N, M = map(int, input().split())
 
cond = [-1] * N
 
for i in range(M):
    s, c = map(int, input().split())
    if cond[s - 1] > -1 and cond[s - 1] != c:
        print(-1)
        exit()
    cond[s - 1] = c

cond = list(map(str, cond))
for i in range(10 ** N):
    si = str(i)
    if N != len(si):
        continue
    ok = True
    for j in range(N):
        if cond[j] == '-1':
            continue
        if si[j] != cond[j]:
            # print(si, si[j], cond[j])
            ok = False
            break
    if ok:
        print(si)
        exit()
print(-1)