N,M=map(int,input().split(' '))
l = [[] for i in range(N)]
for i in range(M):
    s,c=map(int,input().split(' '))
    s = s-1
    l[s].append(c)
ans = []
for i in l:
    if len(set(i)) >=2:
        print(-1)
        exit()
    elif i==[]:
        ans.append(0)
    else:
        ans.append(i[0])
if N==1 and ans[0]==0:
    print(0)
    exit()
if ans[0]==0:
    print(-1)
    exit()
for i in ans:
    print(i,end='')