n, m = map(int, input().split())

s = [0] * m
c = [0] * m

for i in range(m):
    s[i], c[i] = map(int, input().split())
    s[i] -= 1
    
num = [10] * n

flag = False
for i in range(m):
    if num[s[i]] != 10 and num[s[i]] != c[i]:
        #print("dif")
        flag = True
    else:
        num[s[i]] = c[i]
        
for i in range(n):
    if num[i] == 10:
        num[i] = 0
        
if 1 < n and num[0] == 0:
    #print("head is 0")
    flag = True

if flag:
    print(-1)
else:
    print(''.join([str(n) for n in num]))