a,b=map(int,input().split())

x = [list(map(int,input().split())) for _ in range(b)]
y = [-1 for i in range(b)]

t=True
for i in range(b):
    tmp=x[i][0]-1
    tmp1=x[i][1]
    if (y[tmp]>tmp1 or y[tmp]==-1) and not (tmp==0 and tmp1==0) :
        y[tmp]=tmp1

for n,j in enumerate(y):
    if j==-1:
        if n==0 :
            t=not t
            print(-1)
            break
        else:
            y[n]=0
if t:
    print(''.join(map(str,y)))
