import sys

input = sys.stdin.readline



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

L=[-1]*n

if n==1 and m==0:

    print(0)

    sys.exit()

for i in range(m):

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

    s-=1

    if L[s]==-1 or L[s]==c:

        L[s] = c

    else:

        print(-1)

        sys.exit()

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

    print(-1)

    sys.exit()

    

for i in range(n):

    if L[i]==-1:

        if i==0:

            L[i]=1

        else:

            L[i]=0

print(*L,sep="")

import sys

input = sys.stdin.readline



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

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



for i in range(1000):

    S = str(i)

    if len(S)==n:

        for s,c in C:

            s-=1

            if S[s]==str(c):

                True

            else:

                break

        else:

            print(i)

            sys.exit()

print((-1))



import sys

input = sys.stdin.readline
n, m = map(int, input().split())
L = [-1] * n
if n == 1 and m == 0:
    print(0)
    sys.exit()
for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    if L[s] == -1 or L[s] == c:
        L[s] = c
    else:
        print(-1)
        sys.exit()
if L[0] == 0 and n > 1:
    print(-1)
    sys.exit()
for i in range(n):
    if L[i] == -1:
        if i == 0:
            L[i] = 1
        else:
            L[i] = 0
print(*L, sep="")

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
C = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    S = str(i)
    if len(S) == n:
        for s, c in C:
            s -= 1
            if S[s] == str(c):
                True
            else:
                break
        else:
            print(i)
            sys.exit()
print((-1))

-n, m = map(int, input().split()) -L = [-1] * n -if n == 1 and m == 0: -    print(0) -    sys.exit() -for i in range(m): -    s, c = map(int, input().split()) -    s -= 1 -    if L[s] == -1 or L[s] == c: -        L[s] = c -    else: -        print(-1) -        sys.exit() -if L[0] == 0 and n > 1: -    print(-1) -    sys.exit() -for i in range(n): -    if L[i] == -1: -        if i == 0: -            L[i] = 1 +n, m = list(map(int, input().split())) +C = [list(map(int, input().split())) for _ in range(m)] +for i in range(1000): +    S = str(i) +    if len(S) == n: +        for s, c in C: +            s -= 1 +            if S[s] == str(c): +                True +            else: +                break -            L[i] = 0 -print(*L, sep="") +            print(i) +            sys.exit() +print((-1))