import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

data =[]
for i in range(m):
    tmp = [int(n) for n in input().split()]
    data.append(tmp)

end_flg = False
checker = [-1]*3
for num, val in data:
    if checker[num-1] == -1:
        checker[num-1] = val
    elif checker[num-1] != val:
        end_flg = True
        break

checker.reverse()
ans = -1
flg_break = False

for i in range(10):
    if n < 3 and i > 0: continue
    if checker[2] != -1 and checker[2] != i: continue

    for j in range(10):
        if n < 2 and j > 0: continue
        if checker[1] != -1 and checker[1] != j: continue

        for k in range(10):
            if n < 2 and k == 0: continue
            if checker[0] != -1 and checker[0] != k: continue

            if not end_flg:
                ans = 100*i + 10*j + k
                flg_break = True
                break

        if flg_break:
            break
    if flg_break:
        break

if ans == 0:
    ans = -1
print(ans)
