n,m = map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i],c[i] = map(int, input().split())

ans=[1]+[0]*(n-1)

flag = False
for i in range(m):
    ans[s[i]-1]=c[i]
    for j in range(i+1,m):
        if s[i]==s[j]:
            if c[i]!=c[j]:
                flag=True

if flag:
    print(-1)
else:
    print("".join(map(str,ans)))