import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n,m=map(int,input().split())
	ans=[0]*n
	for i in range(m):
		s,c=map(int,input().split())
		if ans[s-1]==0:
			ans[s-1]=c
		elif ans[s-1]!=c:
			print(-1)
			exit(0)
	
	if ans[0]==0 and n>=2:
		print(-1)
		exit(0)
	
	print(*ans,sep="")
	
	
	
	
	

if __name__ == "__main__":
	main()
