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

import sys

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
 
number = [[i for i in range(10)] for i in range(N)]
number[0].pop(0)

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][-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1].append(sc[i][1])
    n_count[sc[i][0]-1] += 1

for i in range(N):
    if n_count[i] > 0:
        print(number[i][-1],end='')
    else:
        print(min(number[i]),end='')