def main():
    n, m = map(int, input().split())

    if m == 0:
        if n == 1:
            print(1)
        elif n == 2:
            print(10)
        else:
            print(100)
        return

    s_ls =[]
    c_ls =[]
    for _ in range(m):
        s, c = map(int, input().split())
        s_ls.append(s)
        c_ls.append(c)

    if n == 1:
        for i in range(0, 10):
            all_ok = True
            for j in range(m):
                if c_ls[j] != i:
                    all_ok = False
                    break
            if all_ok:
                print(i)
                return
        print(-1)
    elif n == 2:
        for i in range(10, 100):
            all_ok = True
            for j in range(m):
                if s_ls[j] == 1:
                    if c_ls[j] == 0:
                        all_ok = False
                        break
                    else:
                        if c_ls[j] != i // 10:
                            all_ok = False
                            break
                else:
                    if c_ls[j] != i % 10:
                        all_ok = False
                        break
            if all_ok:
                print(i)
                return
        print(-1)
    else:
        for i in range(100, 1000):
            all_ok = True
            for j in range(m):
                if s_ls[j] == 1:
                    if c_ls[j] == 0:
                        all_ok = False
                        break
                    else:
                        if c_ls[j] != i // 100:
                            all_ok = False
                            break
                elif s_ls[j] == 2:
                    if c_ls[j] != (i % 100) // 10:
                        all_ok = False
                        break
                else:
                    if c_ls[j] != i % 10:
                        all_ok = False
                        break
            if all_ok:
                print(i)
                return
        print(-1)


main()
