def mapt(fn, *args):
    return tuple(map(fn, *args))
  

def some(d):
    while len(d) < 3:
        d.insert(0, 0)
    return d

def main():
    n, m = mapt(int, input().split(" "))
    data = [mapt(int, input().split(" ")) for _ in range(m)]
    for i in range(0, 10001):
        d = []
        ok = True
        keta = 0
        if i == 0: d.append(0)
        while i > 0:
            keta += 1
            d.append((i % 10))
            i = i//10
        d = some(list(reversed(d)))
        if keta != n: continue
        for index, value in data:
            index -= 1
            if d[index] != value: ok = False
        if ok: print("".join(mapt(str, d))); exit()
    print("-1")

main()