import sys
n, m = map(int, input().split())

num=[0]*n
num[0]=1
for i in range(m):
    s,c=map(int,input().split())
    if num[s-1]==0 or num[s-1]==c:
        num[s-1]=c
    else:
        print(-1)
        sys.exit()

if num[0]==0:
    print(-1)
    sys.exit()
ans=""
for i in num:
    ans=ans+str(i)

print(ans)