#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))





n,m=input2()
sc_list=[]
for _ in range(m):
	sc_list.append(input_array())

result=0
flag=True
result_dict={}
for sc in sc_list:
	sc0=sc[0]
	sc1=sc[1]
	if n!=1 and sc1==0:
		flag=False
		break
	elif sc0 in result_dict:
		if result_dict[sc0]==sc1:
			continue
		else:
			flag=False
			break
	else:
		result+=10**(n-sc0)*sc1
		result_dict[sc0]=sc1

if flag:
	print(result)
else:
	print(-1)