# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = -1

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



N, M = mulinputs()
digits = [0] * 3

datas = dict()
for i in range(M):
    # datas.append(list(mulinputs()))
    s, c = mulinputs()
    if s in datas.keys():
        if datas[s] != c:
            print(-1)
            exit()
    datas[s] = c

for k, v in datas.items():
    digits[k-1] = v

s = ''
for c in digits:
    s = s + str(c)

ans = int(s)
if N > 1 and ans == 0:
    print(-1)
else:
    print(ans)
