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

number = [0]*N
query = [0]*N

for i in range(M):
    s,c = map(int,input().split())
    if query[(s-1)] != 0 and number[(s-1)] != c:
        print('-1')
        exit()
    query[(s-1)] += 1
    number[(s-1)] = c

if N >= 2 and number[0] == 0:
    print('-1')
    exit();

for i in range(len(number)):
    number[i] = str(number[i])

print(''.join(number))