a,b=map(int,input().split())
c=[]
for _ in range(b):
    c.append(list(map(int,input().split())))

for i in range(b):
    for j in range(i):
        if c[i][0]==c[j][0] and c[i][1]!=c[j][1]:
            print(-1)
            exit()
for i in range(b):
    if c[i][1]==0:
        print(-1)
        exit()

result=[0]*a
for i in range(b):
    result[c[i][0]-1]=c[i][1]

if result[0]==0 and a>=2:
    result[0]=1

for i in range(a):
    result[i]=str(result[i])

print(''.join(result))