# -*- 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(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:
        print(-1)
        sys.exit()


A = 0
base = 1
for a in reversed(ans):
    A += a * base
    base *= 10

print(A)