n,m = map(int,input().split())
p = [[int(i) for i in input().split()] for _ in range(m)]
p.sort()

np = list(map(tuple,p))
np = list(set(np))
np.sort()
d = len(np)

np = list(map(list,np))


a = True

if [1,0] in np:
  a = False
  
for x in range(d-1):
  if np[x][0] == np[x+1][0]:
    if np[x][1] != np[x+1][1]:
      a = False
      break
ans = 0
if a:
  if np[0][0] != 1:
    ans = 10 ** (n-1)
    for z in range(d):
      ans += 10 ** (n-np[z][0]) * np[z][1]
    print(ans)
  else:
    for r in range(d):
      ans += 10 ** (n-np[r][0]) * np[r][1]
    print(ans)
    
else:
  print(-1)
  
      