n, m = map(int, input().split())
s = [0]*m
c = [0]*m

for i in range(m):
    s[i], c[i] = map(int, input().split())


ans = 0
ans_list = [0]*n

for i in range(m):
    if ans_list[s[i]-1] == 0:
        ans_list[s[i]-1] = c[i]
    if ans_list[s[i]-1] != c[i]:
        ans = "-1"
    if s[i]-1 == 0:
        if c[i] == 0:
            ans = "-1"

if ans_list[n-1] == 0:
    ans_list[0] = 1

if ans == "-1":
    print(ans)
else:
    for i in range(n):
        ans += ans_list[i]*pow(10, n-i-1)

    print(ans)