n,m = map(int, input().split())

num = 0
dic = {}

for i in range(m):
  s,c = map(int, input().split())
  if n!=1 and s==1 and c==0: 
    print(-1)
    exit()
  if s not in dic:
    dic[s] = c
    num = num + c*(10**(n-s))
  elif c!=dic[s]:
    print(-1)
    exit()

print(num)