from collections import defaultdict, deque
import sys

n, m = map(int, input().split())
dic = defaultdict(int)
for _ in range(m):
    s, c = map(int, input().split())
    if s==1 and c==0:
        print(-1)
        sys.exit()
    elif dic[s]==0 or dic[s] == c:
        dic[s] = c
    else:
        print(-1)
        sys.exit()
        

ans = ["0"]*n

for i in dic:
    ans[i-1] = str(dic[i])
if ans[0] == "0":
    ans[0] = "1"
sol = 0
for i in range(n):
    sol += int(ans[n-i-1])*(10**i)
if sol == 1 and dic[1] != 1:print(0)
else:
    print(sol)