n,m = map(int,input().split())
ans = [-1]*n
can = True

for _ in range(m):
    s,c = map(int,input().split())
    if ans[s-1] == -1 or ans[s-1] == c:
        ans[s-1] = c
    else:
        can = False

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0

if ans[0] == 0:
    ans[0] = 1

res = -1
if can:
    res = 0
    num = 1
    for i in range(n):
        res += ans[n-i-1]*num
        num *= 10

print(res)
