def judge(num):
  l = len(num)
  flag = 0
  for i in range(M):
    if N > l:
      flag = 1
    else:
      if int(num[s[i] - 1]) != c[i]:
        flag = 1
        
  if flag == 0:
    return True
  else:
    return False
    

N, M = map(int, input().split())
s = []
c = []

for i in range(M):
  a, b = map(int, input().split())
  s.append(a)
  c.append(b)
  
for i in range(1000):
  if judge(str(i)):
    print(i)
    exit()
    
print(-1)