n,m = map(int, input().split())
dic = {}
for _ in range(m):
  s,c = input().split()
  if s in dic and dic[s] != c:
    print(-1)
    break
  dic[s] = c
else:
  if '1' in dic and n > 1 and dic['1'] == '0':
    print(-1)
  else:
    if '1' not in dic:
      dic['1'] = '1'

    ans = ""
    for i in range(1,n+1):
      if str(i) in dic:
        ans += dic[str(i)]
      else:
        ans += '0'
    print(ans)