N,M=map(int,input().split())
s=[0]*N
c=[0]*N
for i in range(M):
    s[i],c[i]=map(int,input().split())

A=["-1"]*N
for i in range(M):
    if A[s[i]-1]=="-1" or A[s[i]-1]==c[i]:
        A[s[i]-1]=c[i]
    else:
        print("-1")
        exit()

if N==3:
    if A[0]==0:
        print("-1")
        exit()
if N==2:
    if A[0]==0:
        print("-1")
        exit()

for i in range(N):
    if A[i]=="-1":
        A[i]=0

a=0
for i in range(N):
    a+=A[i]*10**(N-i-1)

print(a)