
#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)]
    for i in range(m):
        s,c = mi()
        s-=1
        slist[s].append(c)
    for i in range(n):
        slist[i] = list(set(slist[i]))
        if not (len(slist[i]) == 1 or len(slist[i]) == 0):
            print(-1)
            exit()

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


main()

