#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	ans = [10, 10, 10]
	judge = "Yes"
	for i in range(M):
		s, c = getlist()
		if c == 0 and s == 1:
			judge = "No"
			break
		elif ans[2 - N + s] == 10 or ans[2 - N + s] == c:
			ans[2 - N + s] = c
		else:
			judge = "No"
			break

	if judge == "No":
		print(-1)
		return

	for i in range(3):
		if ans[i] == 10:
			if i + N == 3:
				ans[i] = 1
			else:
				ans[i] = 0

	answer = str(ans[0]) + str(ans[1]) + str(ans[2])
	print(int(answer))


if __name__ == '__main__':
	main()