#!/usr/bin/env python3

N, M = map(int, input().split())
A = [list(input().split()) for i in range(M)]

if N == 1:
    for i in range(1, 10):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

if N == 2:
    for i in range(10, 100):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

if N == 3:
    for i in range(100, 1000):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

print(-1)