n, m = map(int, input().split())
s = [0]*m
c = [0]*m
ans = [0]*n
flag = 0
for i in range(m):
    s[i], c[i] = map(int, input().split())
for i in range(m):
    for j in range(i+1,m):
        if (s[i] == s[j] and c[i] != c[j]) or i > n:
            flag = 1

for i in range(n):
    for j in range(m):
        if(i == (s[j]-1)):
            ans[i] = c[j]

if(flag == 1 or ans[0] == 0):
    print('-1')
else:
    for i in range(n):
        print(ans[i], end='')
