n,m = map(int,input().split())
q = [list(map(int,input().split())) for i in range(m)]

for i in range(0,1000):
  ans = list(str(i))
  alf = 0
  if len(ans) != n:
    continue
  for j in range(m):
    if int(ans[q[j][0]-1]) == q[j][1]:
      alf += 1
  if alf == m:
    print(i)
    exit()
print(-1)
  