# -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 14:37:00 2020

@author: matsui
"""

N,M=map(int,input().split())
A=[0]*N
B=[0]*N
ans=''
for i in range(M):
    s,c=map(int,input().split())
    if s==1 and c==0: ans=-1
    if B[s-1]==0:
        A[s-1]=c
    else:
        if A[s-1]!=c:
            ans=-1
    B[s-1]=1

if A[0]==0 and B[0]==0:
    A[0]=1


if ans != -1:
    for a in A: 
        ans+=str(a)

print(ans)