import sys

n,m = map(int,input().split())
s = [] ; c = []
for i in range(m) :
  st,ct = map(int,input().split())
  s.append(st) ; c.append(ct)

if n == 1 :
  ans(c[0])
  sys.exit()

ans = [[0,0] for i in range(n)]  
for i in range(m) :
  if s[i] == 1 and c[i] == 0 :
    print(-1)
    sys.exit()
  if ans[s[i]-1][1] == 0 :
    ans[s[i]-1][0] = c[i] 
    ans[s[i]-1][1] = 1
  else :
    if ans[s[i]-1][0] != c[i] :
      print(-1)
      sys.exit()

if ans[0][0] == 0 :
  ans[0][0] = 1

ansn = 0
for i in range(n) :
  ansn += ans[i][0]*10**(n-1-i)
  
print(ansn)