import sys
import math
N, M = map(int, input().split())
NUMS = [list(map(int, input().split())) for _ in range(M)]


def solve():
    if M == 0:
        print("-1")
        return

    for n in range(10 ** (N - 1), 10 ** (N)):
        res = 0
        for s, c in NUMS:
            if str(n)[s - 1] == str(c):
                res += 1
        
        if res == M:
            print(n)
            return
            
    print("-1")