N, M = map(int, input().split())

num = [0, 0, 0]
b = True

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:
        b = False
        
if N == 3 and num[0] == 0: b = False
if N == 2 and num[0] == 0: b = False

if b == False:
    print(-1)
else:
    if N == 3:
        num = [str(x) for x in num]
        num = ''.join(num)
        print(int(num))
    if N == 2: 
        num = num[0:2]
        num = [str(x) for x in num]
        num = ''.join(num)
        print(int(num))
    if N == 1:
        num2 = num[0]
        print(num2)