# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,m = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(m)]

#1桁目に0の指定があれば-1を返す
for s,c in sc:
    if s==1 and c==0:
        import sys

        print("-1")
        sys.exit()

#scを桁数で整理
keta_q_set = [set() for _ in range(n+1)]
for s,c in sc:
    keta_q_set[s].add(c)
ans = ""
for i in range(1,n+1):
    if len(keta_q_set[i])==0:
        if i==1:
            ans+="1"
        else:
            ans+="0"
    if len(keta_q_set[i])==1:
        ans+=str(keta_q_set[i].pop())
    if len(keta_q_set[i])>=2:
        ans="-1"
        break
print(ans)