import sys
n,m = map(int,input().split())
s = [0 for _ in range(m)]
c = [0 for _ in range(m)]
for i in range(m):
    s[i],c[i] = map(int,input().split())
if(max(s) < n):
    print(-1)
    sys.exit()
e = [9 for _ in range(n)]
flag = [0 for _ in range(n)]

for j in range(m):
    if(flag[s[j]-1] == 0):
        e[s[j]-1] = c[j]
    else:
        e[s[j]-1] = min(c[j],e[s[j]-1])
    flag[s[j]-1] = 1
for k in range(n):
    if(flag[k] == 0):
        e[k] = 0
e = map(str,e)
print("".join(e))