n,m = map(int,input().split())
anslist=[0]*n
caplist=[]
for i in range(m):
    a,b=map(int,input().split())
    if not a in caplist:
        anslist[a-1]+=b
        caplist.append(a)
    elif b!=anslist[a-1]:
        print(-1)
        break
else:
    if n==1 and anslist==[0]:
      print(0)
    elif anslist[0]==0:
      print(-1)
    else:
      map=map(str,anslist)
      print(''.join(map))