n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]

#keta = [0 for _ in range(m)]
#num = [0 for _ in range(m)]
ans = True
flag = False
res = 0
k = m

del_list = []
#for i in range(m):
#    keta[i] = l[i][0]
#    num[i] = l[i][1]

new = sorted(l)
#keta = sorted(keta)

for i in range(1, m):
    if new[i][0] == new[i-1][0] and new[i][1] != new[i-1][1]:
        ans = False
    if new[i][0] == new[i-1][0] and new[i][1] == new[i-1][1]:
        #del new[i-1]
        del_list.append(i)
        k -= 1
    if new[i][0] == 1 and new[i][1] == 0:
        ans = False
    elif new[i][0] == 1:
        flag = True
    if new[i][0] == 2:
        flag2 = True
    #if keta[i] == keta[i-1]:
     #   ans = False

if m == 1:
    if new[i][0] == 1 and new[i][1] == 0:
        ans = False
    elif new[i][0] == 1:
        flag = True
    

for i in range(len(del_list)):
    del new[del_list[i]]

#if l in [1, 0]:
#    ans = False
    
if flag:
    pass
else:
    new.append([1, 1])
    
for i in range(k):
    res += new[i][1] * 10**(n-new[i][0])
    
if ans:
    print(res)
else:
    print(-1)