import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n, m = na()

    sc = [na() for _ in range(m)]

    for i in range(1, 1000):
        if len(str(i)) == n:
            tmp = list(map(int, str(i)))
            for s, c in sc:
                s -= 1
                if s == 0 and c == 0:
                    continue
                if tmp[s] != c:
                    break
            else:
                print(i)
                return
    print(-1)

if __name__ == '__main__':
    main()
