n, m = map(int, input().split())
if m == 0:
  if n == 1:
    print(0)
    exit()
  else:
    print(pow(10,n-1))
    exit()
  
dic = {}
for i in range(m):
  s_tmp, c_tmp = list(map(int, input().split()))
  if s_tmp in dic:
    if dic[s_tmp] != c_tmp:
      print(-1)
      exit()
    else:
      continue
  dic[s_tmp] = c_tmp
  
if dic[1] == 0:
  if n != 1:
    print(-1)
    exit()
  else:
    print(0)
    exit()

num = 0
for i in range(1,n+1):
  if i in dic:
    num += dic[i] * pow(10, n-i)
print(num)