n,m= list(map(int, input().split()))
num=[0 for i in range(n)]
for i in range(m):
    tmp=list(map(int,input().split()))
    if tmp[0]==1 and tmp[1]==0:
        print("-1")
        exit(0)
    if num[tmp[0]-1]!=0 and num[tmp[0]-1]!=tmp[1]:
        print("-1")
        exit(0)
    num[tmp[0]-1] = tmp[1]

if num[0]==0 and len(num)!=1:
    num[0] =1
for i in range(n-1):
    print(num[i],end="")
print(num[n-1])