## 1<=N<=3 0<=M<=5
N,M = map(int,input().split())
out = -1

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

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

      if int(str_ans[digit-1]) == val:
        i_count = i_count + 1
        ##print("done")
  #print(i_count)
  if i_count == M:
    out = i
    break

if N == 1 and str(out)[0] == 0:
  print(0)
elif str(out)[0] == 0:
  print(-1)
else:
  print(out)