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


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif n==3 and n==2 and a[0][0] == 0:
    print(-1)
else:
    if n==3 and len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)






