def f():

    N, M = list(map(int, input().split()))

    s = []

    c = []



    for m in range(M):

        _s, _c = list(map(int, input().split()))

        s.append(_s)

        c.append(_c)



    if N == 1:

        rg = list(range(10))

    else:

        rg = list(range(10 ** (N - 1), 10 ** N - 1))



    for i in rg:

        bl = True

        for m in range(M):



            if (i//(10**(N-s[m])))%10 != c[m]:

                bl = False

                break



        if bl:

            return i



    return -1





print((f()))
N, M = list(map(int, input().split()))

S = [input().split() for _ in [0]*M]



for i in range(1000):

    if len(str(i)) != N:

        continue

    for s, c in S:

        if str(i)[int(s)-1] == c:

            continue

        else:

            break

    else:

        print(i)

        break

else:

    print((-1))

def f():
    N, M = list(map(int, input().split()))
    s = []
    c = []
    for m in range(M):
        _s, _c = list(map(int, input().split()))
        s.append(_s)
        c.append(_c)
    if N == 1:
        rg = list(range(10))
    else:
        rg = list(range(10 ** (N - 1), 10**N - 1))
    for i in rg:
        bl = True
        for m in range(M):
            if (i // (10 ** (N - s[m]))) % 10 != c[m]:
                bl = False
                break
        if bl:
            return i
    return -1


print((f()))

N, M = list(map(int, input().split()))
S = [input().split() for _ in [0] * M]
for i in range(1000):
    if len(str(i)) != N:
        continue
    for s, c in S:
        if str(i)[int(s) - 1] == c:
            continue
        else:
            break
    else:
        print(i)
        break
else:
    print((-1))

-def f(): -    N, M = list(map(int, input().split())) -    s = [] -    c = [] -    for m in range(M): -        _s, _c = list(map(int, input().split())) -        s.append(_s) -        c.append(_c) -    if N == 1: -        rg = list(range(10)) +N, M = list(map(int, input().split())) +S = [input().split() for _ in [0] * M] +for i in range(1000): +    if len(str(i)) != N: +        continue +    for s, c in S: +        if str(i)[int(s) - 1] == c: +            continue +        else: +            break -        rg = list(range(10 ** (N - 1), 10**N - 1)) -    for i in rg: -        bl = True -        for m in range(M): -            if (i // (10 ** (N - s[m]))) % 10 != c[m]: -                bl = False -                break -        if bl: -            return i -    return -1 - - -print((f())) +        print(i) +        break +else: +    print((-1))