N,M = map(int,input().split())
ans = ["0"]*N
flag = 1
li = []
for i in range(M):
    s,c = map(int,input().split())
    li.append([s,c])

li.sort()

for i in range(M-1):
    if li[i][0]==li[i+1][0] and li[i][1]!=li[i+1][1]:
        flag = 0

for i in range(M):
    if int(ans[li[i][0]-1])>=li[i][1] or int(ans[li[i][0]-1])==0:
        ans[li[i][0]-1] = str(li[i][1])

ans = "".join(ans)

if len(ans)!=N or ans[0]=="0":
    flag = 0

if flag == 1:
    print(ans)
else:
    print(-1)