# import math
# from itertools import permutations as permus
# from fractions import gcd

# import numpy as np
# import scipy as scp

# 入力の受け取り
n,m = map(int,input().split())

numlist = [10]*n

if m == 0:
    if n == 1:
        ans = 0
    elif n == 2:
        ans = 10
    else:
        ans = 100
else:
    for _ in range(m):
        s,c = map(int,input().split())
        if numlist[s-1] == 10 or numlist[s-1] == c:
            numlist[s-1] = c
        else:
            ans = -1
            break
    else:
        numlist = [0 if num == 10 else num for num in numlist]
        ans = int("".join(map(str,numlist)))

if n != len(str(ans)) and ans != -1:
    ans = -1

print(ans)