#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n,m = mi()
    slist = [[] for i in range(3)]
    flag = True
    if m == 0:
        print(0)
        exit()
    
    for i in range(m):
        s,c = mi()
        s-=1
        if slist[s] and c != slist[s][0]:
            flag = False
        if s == 0 and c == 0:
            flag = False
        slist[s].append(c)
    slist[0] = list(set(slist[0]))
    if n == 1 and slist[0] == [0]:
        print(0)
        exit()
    
    if not flag:
        print(-1)
        exit()


    ansstr = ""

    if slist[0]:
        ansstr+=str(slist[0][0])
    else:
        ansstr += '1'
    
    if n == 1:
        print(ansstr)
        exit()

    for i in range(1,n):
        if slist[i]:
            ansstr+=str(slist[i][0])
        else:
            ansstr+='0'
    print(ansstr)





main()

