# import math

# import bisect

# import heapq

# from collections import deque

import numpy as np



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

s, c = [0] * m, [0] * m

for i in range(m):

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



# replace = [False] * n

number = ['a'] * n

ans = 0

for i in range(m):



    if number[s[i]-1] != 'a' and str(c[i]) != number[s[i]-1]:

        ans = -1

        break



    number[s[i]-1] = str(c[i])



if not ans == -1:

    for i in range(n):

        if i == 0 and number[i] == 'a' and len(number) != 1:

            number[0] = '1'

        elif number[i] == 'a':

            number[i] = '0'

    ans = ''.join(number)



    if n != 1 and number[0] == '0':

        ans = -1

print(ans)





# import math

# import bisect

# import heapq

# from collections import deque

# import numpy as np



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



ans = [-1] * n

safe = True



for i in range(m):

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



    if (n!=1 and s==1 and c==0) or (ans[s-1]!=-1 and c != ans[s-1]):

        safe = False



    ans[s-1] = c





if safe:

    for i in range(n):

        if n!=1 and ans[0]==-1 and i==0:

            ans[0] = 1



        elif ans[i] == -1:

            ans[i] = 0

    print((''.join(str(n) for n in ans)))



else: print((-1))

# import math
# import bisect
# import heapq
# from collections import deque
import numpy as np

n, m = list(map(int, input().split()))
s, c = [0] * m, [0] * m
for i in range(m):
    s[i], c[i] = list(map(int, input().split()))
# replace = [False] * n
number = ["a"] * n
ans = 0
for i in range(m):
    if number[s[i] - 1] != "a" and str(c[i]) != number[s[i] - 1]:
        ans = -1
        break
    number[s[i] - 1] = str(c[i])
if not ans == -1:
    for i in range(n):
        if i == 0 and number[i] == "a" and len(number) != 1:
            number[0] = "1"
        elif number[i] == "a":
            number[i] = "0"
    ans = "".join(number)
    if n != 1 and number[0] == "0":
        ans = -1
print(ans)

# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np
n, m = list(map(int, input().split()))
ans = [-1] * n
safe = True
for i in range(m):
    s, c = list(map(int, input().split()))
    if (n != 1 and s == 1 and c == 0) or (ans[s - 1] != -1 and c != ans[s - 1]):
        safe = False
    ans[s - 1] = c
if safe:
    for i in range(n):
        if n != 1 and ans[0] == -1 and i == 0:
            ans[0] = 1
        elif ans[i] == -1:
            ans[i] = 0
    print(("".join(str(n) for n in ans)))
else:
    print((-1))

-import numpy as np - +# import numpy as np -s, c = [0] * m, [0] * m +ans = [-1] * n +safe = True -    s[i], c[i] = list(map(int, input().split())) -# replace = [False] * n -number = ["a"] * n -ans = 0 -for i in range(m): -    if number[s[i] - 1] != "a" and str(c[i]) != number[s[i] - 1]: -        ans = -1 -        break -    number[s[i] - 1] = str(c[i]) -if not ans == -1: +    s, c = list(map(int, input().split())) +    if (n != 1 and s == 1 and c == 0) or (ans[s - 1] != -1 and c != ans[s - 1]): +        safe = False +    ans[s - 1] = c +if safe: -        if i == 0 and number[i] == "a" and len(number) != 1: -            number[0] = "1" -        elif number[i] == "a": -            number[i] = "0" -    ans = "".join(number) -    if n != 1 and number[0] == "0": -        ans = -1 -print(ans) +        if n != 1 and ans[0] == -1 and i == 0: +            ans[0] = 1 +        elif ans[i] == -1: +            ans[i] = 0 +    print(("".join(str(n) for n in ans))) +else: +    print((-1))