import numpy as np
n,m = map(int,input().split())
base = np.zeros(n)
seen = np.zeros(n)
base[0] = 1
sign = 0

for i in range(m):
  s,c = map(int,input().split())
  if (seen[s-1] == 0) or ((seen[s-1] == 1) and (base[s-1] == c)):
    base[s-1] = c
    seen[s-1] = 1
  else:
    sign = 1
    break
ans = 0
if (sign == 1) or (base[0] == 0):
  ans = -1
else:
  for i in range(1,len(base)+1):
    ans += base[-i]*(10**(i-1))
    
print(int(ans))