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

A = [float('inf') for _ in range(N)]



for i in range(M):

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

    s -= 1

    

    if A[s] != float('inf') and A[s] != c:

        print((-1))

        exit()



    A[s] = min(A[s], c)

    #A[s] = c



for i in range(1, N):

    if A[i] == float('inf'):

        A[i] = '0'

    A[i] = str(A[i]) 



#print(A)



if A[0] == float('inf'):

    if len(A) == 1: A[0] = '0'

    else: A[0] = '1'

else:

    A[0] = str(A[0])



ans = int(''.join(A))



if len(str(ans)) == N: print(ans)

else: print((-1))

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

SC = [[] for _ in range(N)]



error = False

for _ in range(M):

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

    s -= 1

    if SC[s] and SC[s] != c:

        error = True

        break

    else:

        SC[s] = c



if error:

    print((-1))

elif SC[0] == 0 and len(SC) > 1:

    print((-1))

else:

    if not SC[0] and len(SC) == 1:

        SC[0] = 0

    if not SC[0] and len(SC) > 1:

        SC[0] = 1

    if len(SC) > 1 and not SC[1]:

        SC[1] = 0

    if len(SC) > 2 and not SC[2]:

        SC[2] = 0

    print((''.join(map(str,SC))))

N, M = list(map(int, input().split()))
A = [float("inf") for _ in range(N)]
for i in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if A[s] != float("inf") and A[s] != c:
        print((-1))
        exit()
    A[s] = min(A[s], c)
    # A[s] = c
for i in range(1, N):
    if A[i] == float("inf"):
        A[i] = "0"
    A[i] = str(A[i])
# print(A)
if A[0] == float("inf"):
    if len(A) == 1:
        A[0] = "0"
    else:
        A[0] = "1"
else:
    A[0] = str(A[0])
ans = int("".join(A))
if len(str(ans)) == N:
    print(ans)
else:
    print((-1))

N, M = list(map(int, input().split()))
SC = [[] for _ in range(N)]
error = False
for _ in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if SC[s] and SC[s] != c:
        error = True
        break
    else:
        SC[s] = c
if error:
    print((-1))
elif SC[0] == 0 and len(SC) > 1:
    print((-1))
else:
    if not SC[0] and len(SC) == 1:
        SC[0] = 0
    if not SC[0] and len(SC) > 1:
        SC[0] = 1
    if len(SC) > 1 and not SC[1]:
        SC[1] = 0
    if len(SC) > 2 and not SC[2]:
        SC[2] = 0
    print(("".join(map(str, SC))))

-A = [float("inf") for _ in range(N)] -for i in range(M): +SC = [[] for _ in range(N)] +error = False +for _ in range(M): -    if A[s] != float("inf") and A[s] != c: -        print((-1)) -        exit() -    A[s] = min(A[s], c) -    # A[s] = c -for i in range(1, N): -    if A[i] == float("inf"): -        A[i] = "0" -    A[i] = str(A[i]) -# print(A) -if A[0] == float("inf"): -    if len(A) == 1: -        A[0] = "0" +    if SC[s] and SC[s] != c: +        error = True +        break -        A[0] = "1" +        SC[s] = c +if error: +    print((-1)) +elif SC[0] == 0 and len(SC) > 1: +    print((-1)) -    A[0] = str(A[0]) -ans = int("".join(A)) -if len(str(ans)) == N: -    print(ans) -else: -    print((-1)) +    if not SC[0] and len(SC) == 1: +        SC[0] = 0 +    if not SC[0] and len(SC) > 1: +        SC[0] = 1 +    if len(SC) > 1 and not SC[1]: +        SC[1] = 0 +    if len(SC) > 2 and not SC[2]: +        SC[2] = 0 +    print(("".join(map(str, SC))))