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

if M!=0:

    a=[list(map(int,input().split())) for i in range(M)]

    ans=0

    for i in range(M):

        if ans==-1:

            break

        for j in range(M):

            if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:

                ans=-1

                break

#print(ans)####      

    answer=[0]*N

    answer[0]=1

    for i in range(M):

        answer[a[i][0]-1]=a[i][1]

    

    if answer[0]==0 and N>=2:

        ans=-1

#print(answer)######

    if ans==-1:

        print(ans)

    elif answer[0]==0 and N==1:

        print("0")

    else:

        ans=0

        for i in range(N):

            ans+=answer[i]*(10**(N-i-1))

        print(ans)

else:

    if N!=1:

        print((10**(N-1)))

    else:

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

num=[list(map(int,input().split())) for i in range(M)]

ans=[-1]*N

check=True

for i in range(M):

    if ans[num[i][0]-1]==-1:

        ans[num[i][0]-1]=num[i][1]

    elif ans[num[i][0]-1]!=num[i][1]:

        check=False

        break

if ans[0]==-1 and N>1:

    ans[0]=1

elif ans[0]==-1 and N==1:

    ans[0]=0

elif ans[0]==0 and N>1:

    check=False

for i in range(N):

    if ans[i]==-1:

        ans[i]=0



if check==False:

    print("-1")

else:

    answer=0

    for i in range(N):

        answer+=ans[i]*(10**(N-i-1))

    print(answer)

N, M = list(map(int, input().split()))
if M != 0:
    a = [list(map(int, input().split())) for i in range(M)]
    ans = 0
    for i in range(M):
        if ans == -1:
            break
        for j in range(M):
            if a[i][0] == a[j][0] and a[i][1] != a[j][1]:
                ans = -1
                break
    # print(ans)####
    answer = [0] * N
    answer[0] = 1
    for i in range(M):
        answer[a[i][0] - 1] = a[i][1]
    if answer[0] == 0 and N >= 2:
        ans = -1
    # print(answer)######
    if ans == -1:
        print(ans)
    elif answer[0] == 0 and N == 1:
        print("0")
    else:
        ans = 0
        for i in range(N):
            ans += answer[i] * (10 ** (N - i - 1))
        print(ans)
else:
    if N != 1:
        print((10 ** (N - 1)))
    else:
        print("0")

N, M = list(map(int, input().split()))
num = [list(map(int, input().split())) for i in range(M)]
ans = [-1] * N
check = True
for i in range(M):
    if ans[num[i][0] - 1] == -1:
        ans[num[i][0] - 1] = num[i][1]
    elif ans[num[i][0] - 1] != num[i][1]:
        check = False
        break
if ans[0] == -1 and N > 1:
    ans[0] = 1
elif ans[0] == -1 and N == 1:
    ans[0] = 0
elif ans[0] == 0 and N > 1:
    check = False
for i in range(N):
    if ans[i] == -1:
        ans[i] = 0
if check == False:
    print("-1")
else:
    answer = 0
    for i in range(N):
        answer += ans[i] * (10 ** (N - i - 1))
    print(answer)

-if M != 0: -    a = [list(map(int, input().split())) for i in range(M)] -    ans = 0 -    for i in range(M): -        if ans == -1: -            break -        for j in range(M): -            if a[i][0] == a[j][0] and a[i][1] != a[j][1]: -                ans = -1 -                break -    # print(ans)#### -    answer = [0] * N -    answer[0] = 1 -    for i in range(M): -        answer[a[i][0] - 1] = a[i][1] -    if answer[0] == 0 and N >= 2: -        ans = -1 -    # print(answer)###### -    if ans == -1: -        print(ans) -    elif answer[0] == 0 and N == 1: -        print("0") -    else: -        ans = 0 -        for i in range(N): -            ans += answer[i] * (10 ** (N - i - 1)) -        print(ans) +num = [list(map(int, input().split())) for i in range(M)] +ans = [-1] * N +check = True +for i in range(M): +    if ans[num[i][0] - 1] == -1: +        ans[num[i][0] - 1] = num[i][1] +    elif ans[num[i][0] - 1] != num[i][1]: +        check = False +        break +if ans[0] == -1 and N > 1: +    ans[0] = 1 +elif ans[0] == -1 and N == 1: +    ans[0] = 0 +elif ans[0] == 0 and N > 1: +    check = False +for i in range(N): +    if ans[i] == -1: +        ans[i] = 0 +if check == False: +    print("-1") -    if N != 1: -        print((10 ** (N - 1))) -    else: -        print("0") +    answer = 0 +    for i in range(N): +        answer += ans[i] * (10 ** (N - i - 1)) +    print(answer)