N,M = map(int,input().split())
k = [0]*N
flag = 0
count = 0
for i in range(M):
  x,y = map(int,input().split())
  k[x-1] = y
for j in range(10**(N-1),10**N):
  P = str(j)
  for _ in range(N):
    if P[_] == str(k[_]):
      count += 1
      continue
    else:
      break
  if count == N:
    print(j)
    flag += 1
    break
  else:
    count = 0
if flag == 0:
  print(-1)