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

ans = True
flag = False
res = 0
k = m

del_list = []
lis = [[] for i in range(m)]

new = sorted(l)

for i in range(1, m):
    if new[i][1] in lis[i]:
        ans = False
    lis[i].append(new[i][1])
    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_list.append(i-1)
        k -= 1
        
for i in range(m):
    if new[i][0] == 1 and new[i][1] == 0:
        ans = False
    elif new[i][0] == 1 and new[i][1] != 0:
        flag = True
        ans = True
    

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