import sys

from collections import *

import heapq

import math

import bisect

from itertools import permutations,accumulate,combinations,product

from fractions import gcd

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

mod=pow(10,9)+7



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

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

sc.sort()

lst=[-1]*n

for i in range(m):

    s,c=sc[i]

    if n!=1 and s==1 and c==0:

        print((-1))

        quit()

    if lst[s-1]!=-1 and lst[s-1]!=c:

        print((-1))

        quit()

    lst[s-1]=c



ans=0

if lst[0]==-1 and n!=1:

    lst[0]=1

for i in range(n):

    if lst[i]!=-1:

        ans=ans*10 + lst[i]

    else:

        ans=ans*10 + 0



print(ans)
import bisect

import copy

import heapq

import math

import sys

from collections import *

from functools import lru_cache

from itertools import accumulate, combinations, permutations, product

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

sys.setrecursionlimit(500000)

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



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

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

lst=[-1]*n



for i in range(m):

    s,c=sc[i]

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

        lst[s-1]=c

    else:

        print((-1))

        quit()

# print(lst)

for i in range(n):

    if i==0:

        if lst[i]==0 and n!=1:

            print((-1))

            quit()

        elif lst[i]==-1:

            if n==1:

                lst[i]=0

            else:

                lst[i]=1

    elif lst[i]==-1:

        lst[i]=0



print(("".join(map(str,lst))))
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations, accumulate, combinations, product
from fractions import gcd


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


mod = pow(10, 9) + 7
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(m)]
sc.sort()
lst = [-1] * n
for i in range(m):
    s, c = sc[i]
    if n != 1 and s == 1 and c == 0:
        print((-1))
        quit()
    if lst[s - 1] != -1 and lst[s - 1] != c:
        print((-1))
        quit()
    lst[s - 1] = c
ans = 0
if lst[0] == -1 and n != 1:
    lst[0] = 1
for i in range(n):
    if lst[i] != -1:
        ans = ans * 10 + lst[i]
    else:
        ans = ans * 10 + 0
print(ans)

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


sys.setrecursionlimit(500000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n, m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(m)]
lst = [-1] * n
for i in range(m):
    s, c = sc[i]
    if lst[s - 1] == -1 or lst[s - 1] == c:
        lst[s - 1] = c
    else:
        print((-1))
        quit()
# print(lst)
for i in range(n):
    if i == 0:
        if lst[i] == 0 and n != 1:
            print((-1))
            quit()
        elif lst[i] == -1:
            if n == 1:
                lst[i] = 0
            else:
                lst[i] = 1
    elif lst[i] == -1:
        lst[i] = 0
print(("".join(map(str, lst))))

+import bisect +import copy +import heapq +import math -import heapq -import math -import bisect -from itertools import permutations, accumulate, combinations, product -from fractions import gcd +from functools import lru_cache +from itertools import accumulate, combinations, permutations, product +sys.setrecursionlimit(500000) +al = [chr(ord("a") + i) for i in range(26)] +direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] -sc.sort() -    if n != 1 and s == 1 and c == 0: +    if lst[s - 1] == -1 or lst[s - 1] == c: +        lst[s - 1] = c +    else: -    if lst[s - 1] != -1 and lst[s - 1] != c: -        print((-1)) -        quit() -    lst[s - 1] = c -ans = 0 -if lst[0] == -1 and n != 1: -    lst[0] = 1 +# print(lst) -    if lst[i] != -1: -        ans = ans * 10 + lst[i] -    else: -        ans = ans * 10 + 0 -print(ans) +    if i == 0: +        if lst[i] == 0 and n != 1: +            print((-1)) +            quit() +        elif lst[i] == -1: +            if n == 1: +                lst[i] = 0 +            else: +                lst[i] = 1 +    elif lst[i] == -1: +        lst[i] = 0 +print(("".join(map(str, lst))))