n, m = map(int, input().split())
lst = []
for i in range(m):
  s, c = map(int, input().split())
  lst.append([s, c])
ans = -1
for j in range(10 ** n):
  if len(str(j)) != n:
    continue
  for i in range(m):
    if int(str(j)[lst[i][0]-1]) != lst[i][1]:
      break
  else:
    ans = j
    break
print(ans)