
import sys

n, m = map(int,input().split())

b = ''
res = []

if n == 1:
  b = ['b']
elif n == 2:
  b = ['b', 'b']
elif n == 3:
  b = ['b', 'b', 'b']

for _ in range(m):
  res.append(list(input().split()))


for i in res:
  if b[int(i[0]) - 1] == 'b':
    b[int(i[0]) - 1] = i[1]
  elif b[int(i[0]) - 1] != 'b':
    if b[int(i[0]) - 1] == i[1]:
      continue
    print(-1)
    sys.exit()

aaa = ''
for i in range(len(b)):
  if b[i] == 'b':
    aaa += '0'
  else:
    aaa += str(b[i])

if n >= 2 and aaa[0] == '0':
  print(-1)
  sys.exit()
elif n == 3 and aaa[0] == '0' and aaa[1] == '0':
  print(-1)
  sys.exit()

print(aaa)