N,M=map(int,input().split())
S=[0]*M
C=[0]*M
E=False
for m in range(M):
    S[m],C[m]=map(int,input().split())

for n in range(10**(N-1),10**N-1):
    l=0
    for m in range(M):
        s=str(n)
        if s[S[m]-1]==str(C[m]):
            l+=1
    if l==M:
        print(n)
        E=True
        break

if not E:
    print(-1)