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())
	li=[set() for _ in range(n)]
	ans=[]
	for i in range(m):
		s,c=map(int,input().split())
		li[s-1].add(c)
	for i in range(n):
		if len(li[i])>=2:
			print(-1)
			exit(0)
		if li[0]=={0} and n>=2:
			print(-1)
			exit(0)
		elif li[i]==set():
			if i==0:
				ans.append(1)
			else:
				ans.append(0)
		else:
			for k in li[i]:
				ans.append(k)
	
	print(*ans,sep="")
	
	
	
	
	
	
	

if __name__ == "__main__":
	main()
