import sys
n,m=map(int, input().split())
num=[-1]*n
for i in range(m):
    s,c=map(int, input().split())
    if num[s-1]==-1:
        num[s-1]=c
    else:
        if num[s-1]!=c:
            print('-1')
            sys.exit()

for i in range(n):
    if num[i-1]==-1:
        num[i-1]=0
if num[0]==0:
    print('-1')
    sys.exit()
    
num=[str(i) for i in num]
print(''.join(num))