import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


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


n, m = invr()

count = [0] * (n+1)
res = 0
for i in range(m):
    s, c = invr()
    if count[s] == 0:
        count[s] = c
    else:
        if c == count[s]:
            continue
        else:
            print(-1)
            sys.exit()

temp = ""
for i in count:
    temp += str(i)

res = int(temp)
if len(str(res)) != n or res == 0:
    print(-1)
else:
    print(res)
