# -*- coding: utf-8 -*-
import sys


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


ms = 0
upt = [False]*N
ans = [0]*N
for s,c in sc:
    ms = max(N-s,ms)
    if upt[s-1]:
        if ans[s-1] != c:
            print(-1)
            sys.exit()
        else:
            continue        
    else:
        upt[s-1] = True
        ans[s-1] = c

if upt[0]:
    if ans[0] == 0:
        if N>1:
            print(-1)
            sys.exit()
        else:
            print(0)
            sys.exit()

A = 0
base = 1
for i,a in enumerate(reversed(ans)):
    if i>ms:
        A += 1*base
        base *= 10
    else:
        A += a * base
        base *= 10

print(A)