import sys
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
a=[100]*n
for _ in range(m):
    i,j=map(int,input().split())
    a[i-1]=min(j,a[i-1])
for i in range(len(a)):
    if a[i]==100: a[i]=0
ans=a[:]
for i in range(len(ans)-1,-1,-1):
    if ans[i]==0: 
        ans.pop(i)
    else: break
ans=str(int(''.join(map(str,ans))))
num=str(int(''.join(map(str,a))))
if n==len(num) and ans>=num: print(num)
else: print(-1)
