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)

condition = [-1]*3
end_flg = False

for i in range(m):
    if condition[n-data[i][0]] == -1:
        condition[n-data[i][0]] = data[i][1]
    elif condition[n-data[i][0]] != data[i][1]:
        end_flg = True
if end_flg:
    print(-1)
    sys.exit()

ans = -1
for i in range(pow(10, n-1), pow(10, n), 1):
    rank_2 = i // 100
    rank_1 = (i % 100) // 10
    rank_0 = (i % 10) // 1

    if condition[2] != -1 and condition[2] != rank_2: continue
    if condition[1] != -1 and condition[1] != rank_1: continue
    if condition[0] != -1 and condition[0] != rank_0: continue
    if i > pow(10, n-1)-1:
        ans = i
        break

print(ans)
