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)

flag = 0
v_set = np.zeros(N)
#print(v_set)
for i in range(M):
  if len(v_set) != 1 and s[i] == 1 and c[i] == 0:
    flag = 0
    break
  else:
    if v_set[s[i]-1] == 0 or v_set[s[i]-1] == c[i]:
      v_set[s[i]-1] = c[i]
      flag = 1
    else:
      flag = 0
      break
if flag == 0:
  print(-1)
else:
  print(v_set)
  print(str(int(v_set[0]))+str(int(v_set[1]))+str(int(v_set[2])))
  