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:
    r='-1'
    break
  s -= 1
  if r[s]!='0' and r[s]!=c:
    r = '-1'
    break
  r[s] = c
 
all_zero = True
for i in r:
    if i != '0':
        all_zero=False
        break

if all_zero:
    r = '-1'
if not r == '-1':
    if N>1 and r[0] == '0':
        r[0]='1'
    print(''.join(r))
else:
    print(-1)

