#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = map(int, raw_input().split())
s = []
c = []
for i in range(M):
    s_, c_ = map(int, raw_input().split())
    s += [s_]
    c += [c_]

for num in range(1000):
    if len(str(num)) != N:
        continue
    ls = map(int, list(str(num)))
    flag = True
    for i in range(M):
        if ls[s[i] - 1] != c[i]:
            flag = False
    if flag:
        print num
        exit()

print -1