# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 01:52:13 2020

@author: Kanaru Sato
"""

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

found_flag = 0

for i in range(10**(N-1),10**N): #N桁の整数をリストアップ
    str_num = str(i)
    flag_i = 0
    for j in range(0,M):
        if int(str_num[sc[j][0]-1]) == sc[j][1]:
            flag_i += 1
            print(flag_i)
    if flag_i == M:
        found_flag = 1
        int_num = i
        break

if N == 1:
    str_num = "0"
    flag_i = 0
    for j in range(0,M):
        if int(str_num[sc[j][0]-1]) == sc[j][1]:
            flag_i += 1
    if flag_i == M:
        found_flag = 1
        int_num = 0

if found_flag == 0:
    print("-1")
elif found_flag == 1:
    print(int_num)