n, m = map(int, input().split())



li = [0]*n



for i in range(m):

    s, c = map(int, input().split())

    if li[s-1] != 0 and li[s-1] != c:

        print(-1)

        exit(0)

    if s==1 and c==0:

        if n>1:

            print(-1)

            exit(0)

    li[s-1]=c



if n>1 and li[0]==0:

    li[0]=1



for i in range(n):

    print(li[i], end="")

n, m = list(map(int, input().split()))

sc_li = [list(map(int,input().split())) for _ in range(m)]

sc = []

i_s = ""



for i in range(1000):

    flag = True

    i_s= str(i)

    if len(i_s) != n:

        continue

    for j in range(m):

        sc = sc_li[j]

        s = sc[0]

        c = sc[1]

        if int(i_s[s-1]) != c:

            flag = False

    if flag:

        print(i_s)

        exit(0)



print((-1))
n, m = map(int, input().split())
li = [0] * n
for i in range(m):
    s, c = map(int, input().split())
    if li[s - 1] != 0 and li[s - 1] != c:
        print(-1)
        exit(0)
    if s == 1 and c == 0:
        if n > 1:
            print(-1)
            exit(0)
    li[s - 1] = c
if n > 1 and li[0] == 0:
    li[0] = 1
for i in range(n):
    print(li[i], end="")

n, m = list(map(int, input().split()))
sc_li = [list(map(int, input().split())) for _ in range(m)]
sc = []
i_s = ""
for i in range(1000):
    flag = True
    i_s = str(i)
    if len(i_s) != n:
        continue
    for j in range(m):
        sc = sc_li[j]
        s = sc[0]
        c = sc[1]
        if int(i_s[s - 1]) != c:
            flag = False
    if flag:
        print(i_s)
        exit(0)
print((-1))

-n, m = map(int, input().split()) -li = [0] * n -for i in range(m): -    s, c = map(int, input().split()) -    if li[s - 1] != 0 and li[s - 1] != c: -        print(-1) +n, m = list(map(int, input().split())) +sc_li = [list(map(int, input().split())) for _ in range(m)] +sc = [] +i_s = "" +for i in range(1000): +    flag = True +    i_s = str(i) +    if len(i_s) != n: +        continue +    for j in range(m): +        sc = sc_li[j] +        s = sc[0] +        c = sc[1] +        if int(i_s[s - 1]) != c: +            flag = False +    if flag: +        print(i_s) -    if s == 1 and c == 0: -        if n > 1: -            print(-1) -            exit(0) -    li[s - 1] = c -if n > 1 and li[0] == 0: -    li[0] = 1 -for i in range(n): -    print(li[i], end="") +print((-1))