#!/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:
    if key in sc_dict:
        sc_dict[key] = min(value, sc_dict[key])
    else:
        sc_dict[key] = value

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