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

import sys

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 number[0] == 0:
    print(-1)
    sys.exit()
    
for i in range(N):
    print(number[i],end='')