import sys
input = sys.stdin.buffer.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

n, m = map(int, input().split())
a=[-1]*n
v=[False]*n
flg=True
for i in range(m):
    s, c = map(int, input().split())
    if s==1 and c==0 and i!=0:
        flg = False
        break

    if a[s-1]==-1:
        a[s-1]=c
        v[s-1]=True
    elif a[s-1]==c:
        continue
    elif a[s-1]!=c:
        flg=False
        break
if flg:
    for i in range(n):
        if a[i]==-1:
            a[i]=0
    print(*a,sep="")
else:
    print(-1)
