n,m = map(int,input().split())
s,c = [0 for i in range(n)],[0 for i in range(n)]

dict_cand = {}
for i in range(1,n+1):
    if i == n:
        dict_cand[i] = set(range(1,10))
    else:
        dict_cand[i] = set(range(0,10))

for i in range(m):
    s,c = map(int,input().split())
    dict_cand[n+1-s] = dict_cand[n+1-s] & set([c])

flag_number = True
for i in range(1,n+1):
    if len(dict_cand[i]) == 0:
        flag_number = False

if flag_number is True:
    number = 0
    for i in range(1,n+1):
        number += min(dict_cand[i]) * 10**(i-1)
    print(number)
else:
    print(-1)
        