nm = input()
N, M = map(int, nm.split())
sc = []
for i in range(M):
  sc.append(input().split())
r = '0'*N
for (s,c) in sc:
  s = int(s)
  if s>N: return -1
  if r[s] != '0':
    return -1
  r[s] = c

if N==1 and r=='0': return 0

for i in range(N):
  if i==0 and r[i] == '0':
    r[i] = '1'
return int(r)