import numpy as np
N, M = map(int, input().split())
s, c = [], []
for i in range(M):
  tmp_s, tmp_c = map(int, input().split())
  s.append(tmp_s)
  c.append(tmp_c)

v_set = [999 for i in range(N)]
if N == 1:
  for i in range(M):
    if c[i] < v_set[0]:
      v_set[0] = c[i]
  if v_set[0] == 999:
    print(-1)
  else:
    print(v_set[0])
elif N >= 2:
  flag = 0
  for i in range(M):
    if s[i] == 1 and c[i] == 0:
      flag = 0
      break
    else:
      if c[i] < v_set[s[i]-1]:
        v_set[s[i]-1] = c[i]
        flag = 1
  if flag == 0:
    print(-1)
  else:
    for i in range(N):
      if v_set[i] == 999:
        v_set[i] = 0
    if v_set[0] == 0:
      print(-1)
    else:
      out = ''
      for i in range(N):
        out += str(int(v_set[i]))
      print(out)
                 

  