N,M=map(int,input().split())
l=['0' for _ in range(N)]
for _ in range(M):
    s,c=input().split()
    if l[int(s)-1]!='0'and l[int(s)-1]!=c:
        print(-1)
        exit()
    l[int(s)-1]=c
if l.count('0')==N:
    print(-1)
else:
    print(int(''.join(l)))