N,M=map(int, input().split())
s=[]
c=[]
for i in range(M):
    n,a=input().split()
    s.append(int(n))
    c.append(int(a))
a=[1]
S=[0]*N

for i in range(M):
    for j in range(M):
        if s[i]==s[j] and c[i]!=c[j]:
            a.append(-1)

for i in range(M):
    if s[i]==1 and c[i]==0 and N!=1:
        a.append(-1)

for i in range(M):
    S[s[i]-1]=c[i]

if a[-1]==-1:
    print(-1)
else:
    print(''.join(map(str, S)))