import sys
from io import StringIO
import unittest


def exists(value, n, ms, cs):
    if len(value) != n:
        return False
    if all([value[i - 1] == c for i, c in zip(ms, cs)]):
        return True
    return False


def unzip(li):
    return list(map(list, zip(*li)))


def resolve():
    result = -1
    inputs = sys.stdin
    n, m = [int(e) for e in inputs.readline().split()]
    if m == 0:
        print(result)
        return
    m = [input().split() for e in range(m)]
    ms, cs = unzip(m)
    ms = [int(e) for e in ms]

    for i in range(1000):
        if exists(str(i), n, ms, cs):
            result = i
            break
    print(result)
resolve()