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=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:
    lst[0]=1
for i in range(n):
    if lst[i]!=-1:
        ans=ans*10 + lst[i]
    else:
        ans=ans*10 + 0

print(ans)