import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
	s[i], c[i] = map(int, input().split())
ls = [-1] * N
for i in range(M):
	if ls[s[i]-1] == -1 or ls[s[i]-1] == c[i]:
		ls[s[i]-1] = c[i]
	else:
		print(-1)
		sys.exit()

if ls[0] == 0:
	print(-1)
	sys.exit()
for i in range(M):
	if i == 0 and ls[i] == -1:
		print(1, end='')
	elif ls[i] == -1:
		print(0, end='')
	else:
		print(ls[i], end ='')
print()



# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
