n,m=list(map(int,input().split(' ')))
s=[]
for i in range(0,m):
    s.append(list(map(int,input().split(' '))))
K=[0]*n
for i in s:
    a,b=i
    if K[a-1]==0 and b==0:
        K[a-1]=-1
    if K[a-1]==0:
        K[a-1]=K[a-1]+b
    if K[a-1]!=b and b!=0:
        print(-1)
        quit()
for i in s:
    a,b=i
    if K[a-1]==0 and b==0:
        K[a-1]=-1
    if K[a-1]!=b and b!=0:
        print(-1)
        quit()
if n>2:
    if K[0]==-1:
        print(-1)
        quit()
    if K[0]==K[1]==-1:
      print(-1)
      quit()
    if K[1]==-1:
        K[1]=0
    if K[2]==-1:
        K[2]=0
    if K[0]==0:
        K[0]=1
    print(K[0]*100+K[1]*10+K[2])
if n==2:
    if K[1]==-1:
        K[1]==0
    if K[0]==-1:
        print(-1)
        quit()
    if K[0]==0:
      K[0]=1
    print(K[0]*10+K[1])
if n==1:
    if K[0]==-1:
        print(0)
        quit()
    print(K[0])