def solve():

    nm = [int(s) for s in input().split()]
    N = nm[0]
    M = nm[1]
    digits = [-1] * N 
    for _ in range(M):
        sc = [int(s) for s in input().split()]
        s = sc[0]
        c = sc[1]
        if digits[s-1] != -1 and digits[s-1] != c:
            print(-1)
            return
        digits[s-1] = c
    curr = 1
    ans = 0
    for i in range(N-1, -1, -1):
        if digits[i] == -1:
            if i == 0:
                digits[i] == 1
            else:
                digits[i] = 0
        ans += curr * digits[i]
        curr *= 10
    if ans <= 0:
        print(-1)
        return
    print(ans)
solve()
        
    