N, M = map(int, input().split())
b = True
s = [0] * M
c = [0] * M

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


ans = [-1] * N

if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    elif N == 3:
        print(100)
        
else:
    
    if N == 1:
        for i in range(M-1):
            if c[i] != c[i + 1]:
                b = False
        ans[0] = c[0]
    
    elif N == 2:
        
        for i in range(M):
            if s[i] == 1 and c[i] == 0:
                b = False
        
        for i in range(M):
            for j in range(N):
                if s[i] == j + 1:
                    if ans[j] == c[i] or ans[j] == -1:
                        ans[j] = c[i]
                    else:
                        b = False
        
        if ans[0] == -1:
            ans[0] = 1
        if ans[1] == -1:
            ans[1] = 0
                        
    elif N == 3:
        
        for i in range(M):
            if s[i] == 1 and c[i] == 0:
                b = False
        
        for i in range(M):
            for j in range(N):
                if s[i] == j + 1:
                    if ans[j] == c[i] or ans[j] == -1:
                        ans[j] = c[i]
                    else:
                        b = False
        
        if ans[0] == -1:
            ans[0] = 1
        if ans[1] == -1:
            ans[1] = 0
        if ans[2] == -1:
            ans[2] = 0
                    
if b:
    if N == 1:
        print(ans[0])
    elif N == 2:
        print(ans[0] * 10 + ans[1])
    else:
        print(ans[0] * 100 + ans[1] * 10 + ans[2])
else:
    print(-1)