#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
flg = True
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        flg = False
    S[s] = c
    d[s] += 1

if M == 0 and N == 1:
    print(0)
if not flg:
    print(-1)
    exit()
if S[0] == 0:
    if len(S) == 1:
        print(*S)
    else:
        print(-1)
    exit()
print("".join([str(s) for s in S]))


