#!/usr/bin/env python3
import numpy as np


N, M = [int(str) for str in input().strip().split()]
sc = set([tuple([int(str) for str in input().strip().split()]) for _ in range(M)])

sc_dict = {}
for key, value in sc:
    sc_dict[key] = min(value, sc_dict.get(key, 10))

num = int(''.join([str(sc_dict.get(d + 1, 0)) for d in range(N)]))
print(num if len(str(num)) == N else -1)