import sys
N,M = list(map(int, input().split()))

uni = []
keta_dic = {}
max_num = 10**N - 1

num = 0
for _ in range(M):
    s, c = list(map(int, input().split()))
    uni.append((s,c))
    
    if not s in keta_dic.keys():
        keta_dic[s] = c
    else:
        if not keta_dic[s] == c:
            print(-1)
            sys.exit()


zero_keta_max = 0
for k, v in keta_dic.items():
    if v == 0 and k ==1:
        if N == 1:
            pass
        else:
            print(-1)
            sys.exit()
            
    elif v == 0:
        keta = N - k + 1
        if zero_keta_max < keta:
            zero_keta_max = keta
                
zero_max_flag = False

uni = list(set(uni))
for s, c in uni:
    num += 10**(N-s) * c
    if zero_keta_max < s:
        zero_max_flag = True
    
if num > max_num:
    print(-1)
elif zero_max_flag:
    print(num + 10**(N-1))
else:
    print(num)