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
if max(s) > n:
    ans = -1
else:
    for i in range(m):
        if ans_list[s[i]-1] != 0 and ans_list[s[i]-1] != c[i]:
            ans = -1
        if ans_list[s[i]-1] == 0:
            ans_list[s[i]-1] = c[i]

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