# -*- coding: utf-8 -*-
import sys

N, M = map(int, input().split())
s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = map(int, input().split())

TN = 10**(N)-1
SN = 10**(N-1)
if(N == 1):
  SN = 0

for i in range(SN, TN):
  snum = str(i)
  flag = True
  for j in range(M):
    if(int(snum[s[j]-1]) != c[j]):
      flag = False
  if(flag == True):
    print(i)
    sys.exit()
print('-1')
