N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

import sys

#条件0のとき
if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)
    sys.exit()

number = [0]*N
n_count = [0]*N

for i in range(M):
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1] = sc[i][1]
    n_count[sc[i][0]-1] += 1
    
if N == 2:
    if number[0] == number[1] and number[0] == 0:
        print(0)
        sys.exit()

if N == 3:
    if number[0] == number[1] and number[1] == number[2] and number[0] == 0:
        print(0)
        sys.exit()
        
if number[0] == 0 and N != 1:
    print(-1)
    sys.exit()
elif number[0] == 0 and N == 1:
    print(0)
    sys.exit()
    
for i in range(N):
    print(number[i],end='')