import sys

def get_minimun_val(n, rule_dict):
  max_val = 10**n
  min_val = 10**(n-1)
  for i in range(min_val, max_val):
    str_i = str(i)
    flg = True
    for s, c in rule_dict.items():
      if str_i[s-1] == str(c):
        continue
      else:
        flg = False
        break
    if flg:
      return i
  return -1


rule_dict = {}

n, m = map(int, input().split())
res = -1
for i in range(m):
  s, c = map(int, input().split())
  if c == 0 and n == 1:
    print(-1)
    sys.exit()
  if s not in rule_dict:
    rule_dict[s] = c
    continue
  current_c = rule_dict[s]
  if c != current_c:
    print(-1)
    sys.exit()

print(get_minimun_val(n, rule_dict))
