import sys



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, M, *SC = list(map(int, read().split()))



    ans = -1

    for i in range(1000):

        n = str(i)

        if len(n) != N:

            continue

        ok = True

        for s, c in zip(*[iter(SC)] * 2):

            s -= 1

            if s >= N or n[s] != str(c):

                ok = False

                break

        if ok:

            ans = i

            break



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, M, *SC = list(map(int, read().split()))



    A = [-1] * N

    for s, c in zip(*[iter(SC)] * 2):

        s -= 1

        if A[s] != -1 and A[s] != c:

            print((-1))

            return

        else:

            A[s] = c



    if N > 1 and A[0] == 0:

        print((-1))

        return

    elif A[0] == -1:

        if N == 1:

            A[0] = 0

        else:

            A[0] = 1



    for i in range(1, N):

        if A[i] == -1:

            A[i] = 0



    ans = ''.join(map(str, A))



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *SC = list(map(int, read().split()))
    ans = -1
    for i in range(1000):
        n = str(i)
        if len(n) != N:
            continue
        ok = True
        for s, c in zip(*[iter(SC)] * 2):
            s -= 1
            if s >= N or n[s] != str(c):
                ok = False
                break
        if ok:
            ans = i
            break
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *SC = list(map(int, read().split()))
    A = [-1] * N
    for s, c in zip(*[iter(SC)] * 2):
        s -= 1
        if A[s] != -1 and A[s] != c:
            print((-1))
            return
        else:
            A[s] = c
    if N > 1 and A[0] == 0:
        print((-1))
        return
    elif A[0] == -1:
        if N == 1:
            A[0] = 0
        else:
            A[0] = 1
    for i in range(1, N):
        if A[i] == -1:
            A[i] = 0
    ans = "".join(map(str, A))
    print(ans)
    return


if __name__ == "__main__":
    main()

-    ans = -1 -    for i in range(1000): -        n = str(i) -        if len(n) != N: -            continue -        ok = True -        for s, c in zip(*[iter(SC)] * 2): -            s -= 1 -            if s >= N or n[s] != str(c): -                ok = False -                break -        if ok: -            ans = i -            break +    A = [-1] * N +    for s, c in zip(*[iter(SC)] * 2): +        s -= 1 +        if A[s] != -1 and A[s] != c: +            print((-1)) +            return +        else: +            A[s] = c +    if N > 1 and A[0] == 0: +        print((-1)) +        return +    elif A[0] == -1: +        if N == 1: +            A[0] = 0 +        else: +            A[0] = 1 +    for i in range(1, N): +        if A[i] == -1: +            A[i] = 0 +    ans = "".join(map(str, A))