## 入力 ##
N,M = map(int,input().split())
digit_val = {}
for i in range(1,M+1):
  digit_val[i] = list(map(int,input().split()))

out = -1

for i in range(1,1000):
  str_ans = str(i)
  length = len(str_ans)
  i_count = 0 
  ## 桁数が同じか確認 ##
  if length == N:
    ## 一致確認 ##
    for s in range(1,len(digit_val)+1):
      ## 指示値 ##
      digit = digit_val[s][0]
      val = digit_val[s][1]
      if int(str_ans[digit-1]) == val:
        i_count = i_count + 1
  if i_count == M:
    out = i
    break
print(out)