n,m=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(m)]
n1=[0]*n
nc=[0]*n
for i in range(m):
    if n1[x[i][0]-1]==0:
        n1[x[i][0]-1]+=x[i][1]
        nc[x[i][0]-1]+=1
    elif nc[x[i][0]-1]!=0 and n1[x[i][0]-1]!=x[i][1]:
        print(-1)
        exit()
while True:
    if n1[0]==0:n1.pop(0)
    if sum(n1)==0:
        print(0)
        exit()
    else:break
print(''.join(map(str,n1)))