#!/usr/bin/env python
import sys
from io import StringIO

def guess(rl=sys.stdin.readline):
    n, m = [int(x) for x in rl().split(' ')]

    digits = [-1 for x in range(n)]
    for i in range(m):
        s, c = [int(x) for x in rl().split(' ')]
        if digits[s-1] >= 0 and digits[s-1] != c:
            return -1
        else:
            digits[s-1] = c

    hasNonZero = False
    if n == 1 and digits[0] < 0:
        return 0
    if digits[0] == 0:
        return -1

    for i in range(len(digits)):
        if digits[i] > 0:
            hasNonZero = True
        elif digits[i] < 0:
            if hasNonZero:
                digits[i] = 0
            else:
                digits[i] = 1

    ans = 0
    for d in digits:
        ans = ans*10 + d
    return ans


print(guess())
