N,M=list(map(int,input().split()))



C=[-1]*N



for i in range(M):

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

    if C[s-1]==-1:

        C[s-1]=c

    elif C[s-1]!=-1:

        if C[s-1]!=c:

            print((-1))

            exit()



if N==1 and C[0]==0:

    print((0))

    exit()



if N==1 and C[0]==-1:

    print((0))

    exit()



ans=""

for i in range(N):

    if i == 0 and C[i] == 0:

        print((-1))

        exit()

    if C[i]==-1:

        if i==0:

            ans+="1"

        else:

            ans+="0"

    else:

        ans+=str(C[i])

print(ans)





N,M=list(map(int,input().split()))



S=[]

C=[]



for i in range(M):

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

    S.append(s-1)

    C.append(c)



for n in range(1000):

    ns=str(n)

    nl=list(ns)

    if len(ns)!=N:

        continue

    f=True

    for m in range(M):

        if nl[int(S[m])]!=str(C[m]):

            f=False

            break

    if f==True:

        print(n)

        exit()

print((-1))







N, M = list(map(int, input().split()))
C = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if C[s - 1] == -1:
        C[s - 1] = c
    elif C[s - 1] != -1:
        if C[s - 1] != c:
            print((-1))
            exit()
if N == 1 and C[0] == 0:
    print((0))
    exit()
if N == 1 and C[0] == -1:
    print((0))
    exit()
ans = ""
for i in range(N):
    if i == 0 and C[i] == 0:
        print((-1))
        exit()
    if C[i] == -1:
        if i == 0:
            ans += "1"
        else:
            ans += "0"
    else:
        ans += str(C[i])
print(ans)

N, M = list(map(int, input().split()))
S = []
C = []
for i in range(M):
    s, c = list(map(int, input().split()))
    S.append(s - 1)
    C.append(c)
for n in range(1000):
    ns = str(n)
    nl = list(ns)
    if len(ns) != N:
        continue
    f = True
    for m in range(M):
        if nl[int(S[m])] != str(C[m]):
            f = False
            break
    if f == True:
        print(n)
        exit()
print((-1))

-C = [-1] * N +S = [] +C = [] -    if C[s - 1] == -1: -        C[s - 1] = c -    elif C[s - 1] != -1: -        if C[s - 1] != c: -            print((-1)) -            exit() -if N == 1 and C[0] == 0: -    print((0)) -    exit() -if N == 1 and C[0] == -1: -    print((0)) -    exit() -ans = "" -for i in range(N): -    if i == 0 and C[i] == 0: -        print((-1)) +    S.append(s - 1) +    C.append(c) +for n in range(1000): +    ns = str(n) +    nl = list(ns) +    if len(ns) != N: +        continue +    f = True +    for m in range(M): +        if nl[int(S[m])] != str(C[m]): +            f = False +            break +    if f == True: +        print(n) -    if C[i] == -1: -        if i == 0: -            ans += "1" -        else: -            ans += "0" -    else: -        ans += str(C[i]) -print(ans) +print((-1))