N,M=map(int,input().split())
ans=['0']*N
for i in range(M):
    s,c = map(int,input().split())
    if ans[s-1]=='0' or c<int(ans[s-1]):
        ans[s-1]=str(c)
if ans[0]=='0':
    print('-1')
else:
    ans=''.join(ans)
    print(ans)