# n, r = input().split(" ")
# n=int(n)
# r=int(r)
# if n<10:
#     print((100*(10-n))+r)
# else:
#     print(r)
# answer = int(r) + 100 * (10 - int(n))
# print(answer)
# import math
# n, k = input().split(" ")
# n= int(n)
# k= int(k)
# dig = (math.floor(math.log(n) / math.log(k)) + 1)
# print(dig)

# n = int(input())
# x = input().split(" ")
# x = [int(i) for i in x]
# answer = 0
# for index,i in enumerate(x):
#     answer += pow((i - index), 2)
# print(answer)

# n = int(input())
# x = list(map(int, input().split()))
# m = round(sum(x)/n)
# answer = 0
# for i in x:
#     answer += (i-m)**2
# print(answer)

N, M = input().split(" ")
N, M = int(N), int(M)

if not (1 <= N <=3 and 0 <= M <= 5):
    print("-1")
    exit(0)

arr = []

for _ in range(M):
    s, c = input().split(" ")
    s, c = int(s), int(c)
    if not (1 <= s <= N and 1 <= c <= 9):
        print("-1")
        exit(0)
    arr.append((s, c))


arr.sort(key=lambda x:x[0])

check_val = set()
res = []
for i in arr:
    if i[0] not in check_val:
        res.append(i)
        check_val.add(i[0])

ans = ""
for i,x in enumerate(arr):
    if x[0] != i+1:
        ans += str(0)
    else:
        ans += str(x[1])
print(ans)