n, m = map(int, input().split())
T = []
A = [str(0) for _ in range(n)]
for i in range(m):
  s, t = map(int, input().split())
  T.append([s, t])
f = True
for i in range(m):
  for j in range(i, m):
    if (T[i][0] == T[j][0] and T[i][1] != T[j][1]) or (T[i][0] == 1 and T[i][1] == 0):
      f = False
      break
  A[T[i][0]-1] = str(T[i][1])

if f: print("".join(A))
else: print(-1)