import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(N):
    return sum(map(int, str(N)))


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    SC = [il() for _ in range(M)]
    ret = [0] * 3
    for s, c in SC:
        if ret[s - 1] == 0 or ret[s - 1] == c:
            ret[s - 1] = c
        else:
            print(-1)
            exit()
    else:
        q = ''.join(map(str, ret))
        print(q if q[0] != str(0) and len(q) == 3 else -1)


if __name__ == '__main__':
    main()
