N,M = map(int,input().split())
s = []
c = []
flg = [0]*N
ok_flg = True
ans = [0]*N
answer = "-1"
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
#print("s:",s,",c:",c)
for i in range(len(s)):
#  print(ans)
#  print(10**s[i] , 10**(N))
  if 10**s[i] > 10**(N):
    ok_flg = False
    break
  if flg[s[i]-1]  == 0:
#    print("for :",s[i],c[i])
    ans[s[i]-1] = c[i]
    flg[s[i]-1] = 1
  else:
    if ans[s[i]-1] != c[i]:
      answer = -1
      ok_flg = False
      break
is_zero = 0
if ok_flg :
  answer = ""
  for i in ans:
    answer += str(i)
    is_zero += i
  if is_zero == 0:
    answer = "-1"
  if M == 0:
    answer = "0"
  
print(int(answer))