def check():
    N, M = map(int, input().split())
    keta = ['?']*N
    
    for _ in range(M):
        s, c = map(int, input().split())        
        if keta[s-1] == '?' or keta[s-1] == c:
            keta[s-1] = c
        else:
            return -1
    if keta[0] == 0:
        return -1
    
    keta = [0 if num == '?' else num for num in keta]
    
    return ''.join(map(str, keta))
print(check())