# -*- coding: utf-8 -*-
"""
Created on Sun Mar  1 21:17:39 2020

@author: naoki
"""
import sys
N, M = map(int, input().split())
sc = [list(map(int,input().split())) for _ in range(M)]


for num in range(10**(N)):
    switch = True
    for condition in sc:
        if len(list(str(num))) >= condition[0]:
            if list(str(num))[condition[0]-1] == str(condition[1]):
                continue
            else:
                switch = False
        else:
            switch = False
    if switch == True:
        print(num)
        sys.exit()

print(-1)