N, M = map(int, input().split())
A = [-1] * N
valid = True
for i in range(M):
  s, c = map(int, input().split())
  if A[s - 1] < 0:
    A[s - 1] = c
  elif A[s - 1] != c:
    valid = False
if A[0] < 0:
  A[0] = 1
if A[0] < 1:
  valid = False
for i in range(1, N):
  if A[i] < 0:
    A[i] = 0
print(''.join([str(a) for a in A]) if valid else -1)