import sys
from io import StringIO
import unittest

def resolve():
    N, M = [int(x) for x in input().rstrip().split()]

    digits = [-1] * N

    for _ in range(M):
        S, C = [int(x) for x in input().rstrip().split()]
        index = S -1

        if digits[index] != -1 and digits[index] != C:
            print("-1")
            return

        digits[index] = C


    if(digits[0] == 0):
        print("-1")
        return

    if(digits[0] == -1):
        digits[0] = 1

    for d in digits:
        if d == -1:
            d = 0
        print(d, end="")

    print()

resolve()