N, M = map(int, input().split())
ans = []
lst = [[] for i in range(3)]
for i in range(M):
    a, b = map(int, input().split())
    if b not in lst[a-1]:
        lst[a-1].append(b)
for i in range(3):
    if len(lst[i]) > 1:
        print(-1)
        exit()
    
    elif not lst[i]:
        if i == 0 and N == 3:
            ans.append(str(1))
        elif i == 1 and N == 2:
            ans.append(str(1))
        else:
            ans.append(str(0))
        
    else: 
        ans.append(str(lst[i][0]))

num = ''.join(ans)
if int(num)//(10**(N-1)) >= 1 and int(num)//(10**(N-1)) < 10:
    print(int(num))
elif int(num) == 0 and N == 1:
    print(0)
else:
    print(-1)