import sys
import os


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

    N, M = list(map(int, sys.stdin.readline().split()))
    lines = [line.rstrip() for line in sys.stdin.readlines()]

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

    ret = -1
    for n in range(pow(10, N-1), pow(10, N)):
        flg = True
        for line in lines:
            s, c = map(int, line.split())
            t = str(n)
            if t[s-1] != str(c):
                flg = False

        if flg:
            ret = n
            break

    print(ret)


if __name__ == '__main__':
    main()
