import sys

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

num = [0]*n
count = [0]*n

for _ in range(m):
    b,c = map(int, input().split())
    if num[b-1] != c and count[b-1] > 0:
        print(-1)
        sys.exit()
    count[b-1]+=1
    num[b-1] = c
    

if n == 3 and num[0] == 0:    
    print(-1)
    sys.exit()
elif n == 2 and num[0] == 0:
    print(-1)
    sys.exit()

ans = ""
for i in range(n):
    ans+=str(num[i])
print(ans)
