n, m = map(int, input().split())
num = [-1] * n
ans = 0
if m == 0:
    ans = -1

for i in range(m):
    s, c = map(int, input().split())
    if num[s-1] == c or num[s-1] == -1:
        num[s-1] = c
    else:
        ans = -1
        break
        
if n == 3 and num[0] <= 0:
    ans = -1
elif n == 2 and num[0] <= 0:
    ans = -1
    
if not ans == -1:
    l = ''
    for j in num:
        if j == -1:
            l += '0'
        else:
            l += str(j)
    ans = int(l)        
print(ans)
    