n, m = map(int, input().split())
s = [-1] * 3
si_t = [None, 3, 2, 1]
for i in range(m):
    si, ci = map(int, input().split())
    
    if si_t[si] > n:
        print(-1)
        exit()
    
    if ci == 0 and n == si_t[si]:
        print(-1)
        exit()
    
    if s[si-1] == -1:
        s[si-1] = ci
    
    elif s[si-1] != ci:
        print(-1)
        exit()

    s[si-1] = min(s[si-1], ci)

ans = ""
for i in range(n):
    if s[i] == -1:
        s[i] = 0
    ans += str(s[i])
print(int(ans))
