import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n, m = tin()
	dd = [set() for _ in range(n)]
	for _ in range(m):
		s, c = tin()
		dd[s-1].add(c)
	for s in dd:
		if len(s) > 1:
			return -1
	dd=[list(d) for d in dd]
	if dd[0]==[0]:
		return -1
		
	for i in range(n):
		if len(dd[i])==0:
			dd[i] = [0] if i != 0 else [1]
	ret = ''.join([str(d[0]) for d in dd])
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)