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

s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))

if N == 1:
    if M == 0:
        print(1)
        exit()

    for x in range(1, 10):
        Sx = str(x)
        for xx in range(M):
            if s[xx] == 1 and str(c[xx]) == Sx[0]:
                pass
            else:
                break

            if xx == M-1:
                print(x)
                exit()

    print('-1')
    exit()


if N == 2:
    if M == 0:
        print(10)
        exit()

    for y in range(10, 100):
        Sy = str(y)
        for yy in range(M):
            if s[yy] == 1 and str(c[yy]) == Sy[0] or \
                s[yy] == 2 and str(c[yy]) == Sy[1]:
                pass
            else:
                break

            if yy == M-1:
                print(y)
                exit()

    print('-1')
    exit()


if N == 3:
    if M == 0:
        print(100)
        exit()

    for z in range(100, 1000):
        Sz = str(z)
        for zz in range(M):
            if s[zz] == 1 and str(c[zz]) == Sz[0] or \
                s[zz] == 2 and str(c[zz]) == Sz[1] or \
                s[zz] == 3 and str(c[zz]) == Sz[2]:
                pass
            else:
                break

            if zz == M-1:
                print(z)
                exit()

    print('-1')
    exit()
