from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

ans = MOD
n, m = map(int, input().split())
num_list = [-1]* n
for i in range(m):
    loc, num = map(int, input().split())
    if (loc, num) == (1, 0):
        ans = -1
    if (num_list[loc-1] == -1 ) or (num_list[loc - 1] == num):
        num_list[loc - 1] = num
    else:
        ans = -1

if num_list[0] == -1: 
    num_list[0] = 1

num_array = np.array([num_list])
num_array[num_array < 0] = 0
dig_array = 10 ** np.arange(n)
ans_array = num_array * dig_array[::-1]

if ans == -1:
    print(-1)
else:
    print(ans_array.sum())



